Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using Ajax request in a Liferay portlet

    • 0
    • 3
    • 3
    • 1
    • 0
    • 0
    • 0
    • 0
    • 1.56k
    Comment on it

    Ajax Request in Liferay Portlet:- In below code we will show you how you will call the ajax request in the Liferay. We can pass the aui form values to the PatientSearch portlet then get the result from database and display records in HTML table.

    search.jsp

    <portlet:actionURL var="addItemURL" name="searchPatientAjaxCall"/>
    <aui:script use="aui-io-request,aui-node">
    
         Liferay.provide(window,'submitItemForm',
             function() {
    
                    var A = AUI();
                      A.io.request('<%= addItemURL %>',{
                          method: 'POST',
                          form: { id: '<portlet:namespace />addItemForm' },
                          on: {
                              success: function(){
    
                                $('#patientsrchlist').html(this.get('responseData'));
                              }
                          }
                     }); 
    
                }
             }); 
    </aui:script>
    
    <aui:form method="POST" name="addItemForm" id="addItemForm" action="#">
            <ul class="clearfix">
                <li>
                    <div class="select-box">
                    <i class="arrow"></i>
                    <aui:select name="selectLoadOption" id="srchOPT">
                            <aui:option value="All">All</aui:option>
                            <aui:option value="Patient">Patient</aui:option>
                            <aui:option value="Tag">Tag</aui:option>
                    </aui:select>
                    </div>
                </li>
                <li>
                    <div class="select-box search-btn">
                    <aui:input type="text" name="itemName" id="srchItem"></aui:input>
                    <input type="button" class="search-icon" onclick="submitItemForm();" />
                    </div>
                </li>
            </ul>
    </aui:form>
    
            <table id="patientsrchlist">
                <thead>
                        <tr>
                        </tr>
                </thead>
    
                <tbody>
    
                            <tr>
                              <td class="first" colspan="6"><a href="#" target="_self" ></a></label></td> 
    
                            </tr>
                </tbody>
    
            </table>  
    

    PatientSearch.java

    public class PatientSearch extends MVCPortlet {
    
          @ProcessAction(name="searchPatientAjaxCall")
        public  void searchPatientAjaxCall(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortletException
        {
    
             System.out.println("srchOPT------->     :"+ParamUtil.getString(originalRequest,"srchOPT"));
             System.out.println("srchItem------->     :"+ParamUtil.getString(originalRequest, "srchItem"));
    
             String content="";
             char ch='%';
             String itemName="";
             String selectLoadOption="";
             String url="";
    
    
                    long ownerId=PortalUtil.getUserId(actionRequest);
                    System.out.println("Dentist userId:-------   "+PortalUtil.getUserId(actionRequest));
                    System.out.println("Item Submitted: " + itemName);
                    System.out.println("Item Submitted: " + selectLoadOption);
    
    
                        //below method can fetch the records from database on basis of ownerId and It's name
                      List<PatientRecords> patientRecords=PatientRecordsLocalServiceUtil.searchPatientRecordsByOwnerIdAndName(ownerId, itemName, itemName);
    
                      System.out.println(patientRecords);
    
                      for(PatientRecords patientRecord : patientRecords)
                      {
                          content="<tr>"+"<td class=\"first\" colspan=\"6\">"+"<a href=\"#\" target=\"_self\">"+patientRecord.getFname()+" "+patientRecord.getLname()+"</a>"+
                                  "</label>"+"</td>"+"</tr>"+content; 
                      }
    
    
    
                    HttpServletResponse httpResp = PortalUtil.getHttpServletResponse(actionResponse);
                    httpResp.setContentType("text");
                    httpResp.getWriter().print(content);
                    httpResp.flushBuffer();
    
    
    
        }
    
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: