Posts

Showing posts with the label ajax

Creating the URL programmtically

Hi, Below is the code ,to create the different types of request URL. As we know in Liferay we have 3 types of URL 1.ActionRequest 2.RenderRequest 3.ResourceRequest. //Create Render URL PortletURL renderURL = PortletURLFactoryUtil.create( actionRequest,PortalUtil.getPortletId(actionRequest), themeDisplay.getLayout().getPlid(), "0"); renderURL.setParameter("customparam","customvalue"); actionResponse.sendRedirect(renderURL.toString()); If you want to create the ActionRequest put 1 instead of 0 in the last argument. We can check the code in the  PortletURLImpl class of liferay if (_lifecycle.equals(PortletRequest.ACTION_PHASE)) { _reservedParameters.put("p_p_lifecycle", "1"); } else if (_lifecycle.equals(PortletRequest.RENDER_PHASE)) {

Ajax Implementation in the Liferay

Creating the Resource URL Liferay's default uses the resource url for ajax requests          <portlet:resourceURL id="addResource" var="addResourceURL">         </portlet:resourceURL> Creating the Ajax function creating the Jquery  ajax function function <portlet:namespace/>getEntries(){                 var url = "${addResourceURL}";                         $.ajax({                                 type : "POST",                                 url : url,                                 dataType : "JSON",                 ...

Submitting the form with ajax(using alloy UI) i.e with out page refresh

    In rare it may happens, you have to submit the form with out refresh the page (actionURL ) and save the parameters in the DB.    Jus Copy the below code , Here i am using alloy UI to submit the form and here not need to append any parametrs to the URL .you will get the parameters values from request parameters. <portlet:actionURL var="formsubmissionURL" /> <aui:script use="aui-io-request,aui-node" > Liferay.provide(window,'submitForm', function() { var A = AUI(); A.io.request('${formsubmissionURL}',{ method: 'POST', form: { id: '<portlet:namespace />fm' }, on: { success: function(){     }   }   });   }); </aui:script > <aui:form action="#" method="POST" id="fm" name="fm" >      <aui:input type="text" name="name"/>      <aui:button type="submit" value="Save" /...