Posts

Refreshing the portlet through the javascript

Some times it may require our portlet when some action performed. We can refresh liferay portlet through the javascript. <script type="text/javascript"> jQuery(document).ready(function() {           Liferay.Portlet.refresh('#p_p_id_ testjson_WAR_testjson _'); } </script> Bold word is the portlet name

Creation of URL in class

Some times it may require you to create url in class. Its quite easy task to do , Here you follow as , ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest. getAttribute(WebKeys.THEME_DISPLAY); long plid = PortalUtil.getPlidFromPortletId(themeDisplay.getScopeGroupId(),<portlet-name>);          PortletURL portletURL = PortletURLFactoryUtil.create(actionRequest ,<portlet-name>, plid ,PortletRequest.RENDER_PHASE);          portletURL.setWindowState(LiferayWindowState.POP_UP);          portletURL.setPortletMode(LiferayPortletMode.VIEW);          portletURL.setProperty("portletName", <portlet-name>);          portletURL.setParameter("type", "add"); For Custom portlet name will be some thing as like this <name>_WAR_<name>

Hiding the portlet

In some seceniros you may need to hide the portlet, In liferay it is easy as just add the attribute. renderRequest.setAttribute(WebKeys.PORTLET_CONFIGURATOR_VISIBILITY, false); That it !!! Above renderRequest  will set  in hiding 

Accessing JSON through javascript in custom portlet

Image
Scenrio:           Accessing the other custom portlet JSON services in our custom portlet through the javascript. Step:1 Enable remote-servie = true in service.xml as shown and build service to generate the services <service-builder package-path="com.liferay.testjson"> <namespace>custom</namespace>          <entity name="jsontest" remote-service="true" local-service="true" uuid="true">                      <column name="id" type="int" primary="true" />                       <column name="name" type="String"></column>                     <column name="desc" type="String"></column>     </entity>   </service-builder> Step2:   Open the class XXXXServiceImpl.class ...

Focusing the form field in Liferay

  Whenever we create from in liferay ,it is required cursor to focus on the first field.   Suppose we can have form like this   <aui:from name="fm" method="post" action="${updateActionURL}">             <aui:input  name="title" label = "Title"/>        <aui:input  name="desc" label = "Desc"/>       <aui:button type="submit" value ="save"/> <.aui:form>  If we think title should be highlited on page load , following script is also required. <aui:script> Liferay.Util.focusFormField(document.<portlet:namespace/>fm.<portlet:namespace/>title); </aui:script> Deploy your project and refresh your page . We can see the first field is highlighted. These source are avaliable in the follwing path.       portal-web/docroot/html/js/liferay

Success message and Error message in liferay

Success Message                   In Class                           SessionMessages.add(request, "record-updated");                In JSP                           <liferay-ui:success key="record-updated" message="record-updated-sucessfully" />                Language.properties                            record-updated  = Your record updated successfully.          ...

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" /...