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.55k
    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.


    <portlet:actionURL var="addItemURL" name="searchPatientAjaxCall"/>
    <aui:script use="aui-io-request,aui-node">
             function() {
                    var A = AUI();
            '<%= addItemURL %>',{
                          method: 'POST',
                          form: { id: '<portlet:namespace />addItemForm' },
                          on: {
                              success: function(){
    <aui:form method="POST" name="addItemForm" id="addItemForm" action="#">
            <ul class="clearfix">
                    <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>
                    <div class="select-box search-btn">
                    <aui:input type="text" name="itemName" id="srchItem"></aui:input>
                    <input type="button" class="search-icon" onclick="submitItemForm();" />
            <table id="patientsrchlist">
                              <td class="first" colspan="6"><a href="#" target="_self" ></a></label></td> 

    public class PatientSearch extends MVCPortlet {
        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);
                      for(PatientRecords patientRecord : patientRecords)
                          content="<tr>"+"<td class=\"first\" colspan=\"6\">"+"<a href=\"#\" target=\"_self\">"+patientRecord.getFname()+" "+patientRecord.getLname()+"</a>"+
                    HttpServletResponse httpResp = PortalUtil.getHttpServletResponse(actionResponse);

 0 Comment(s)

Sign In

Sign up using

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: