16 May, 2013

Spring MVC Portlet AJAX call using Resource URL

You can follow below steps to make AJAX call using resource URL

  1. Create Spring MVC portlet 
  2. In view.jsp write below code to generate resource URL    
    • <portlet:resourceURL var='myInfo' id='myInfo' />
  3. Write AJAX call scriptin view.jsp

    <script type="text/javascript">

    function loadMyInfo(){
        var myInfoUrl = "<%=myInfo%>";
            url: myInfoUrl ,
            type: 'GET',
            success: function(data){
                var obj = $.parseJSON(data);
  4. Go to controller and write method as given below
            public void getMyInformation(ResourceRequest request, ResourceResponse response) throws IOException  {
                JSONObject json = JSONFactoryUtil.createJSONObject();
                ThemeDisplay themeDisplay  =(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
                User user = themeDisplay .getUser();
                json.put("firstName",user != null ? user.getFirstName() :"");
                json.put("lastName",user != null ? user.getLastName() :"");
                }catch (Exception e) {
  5. Now deploy your portlet and see the result  ,On load it will make ajax call and render the data

Popular Posts

Featured Post

Liferay 7.3 compatibility matrix

Compatibility Matrix Liferay's general policy is to test Liferay Portal CE against newer major releases of operating systems, open s...