Thursday 14 September 2017

Liferay Default Theme Velocity Variables

List of velocity variables in theme template


Liferay Default Theme Velocity Variables tutorial will show light on the available velocity variables in Liferay theme. As you already know, Liferay already set parent variables in init.VM (/Liferay-home/tomcat/web apps/ROOT/HTML/themes/unstyled-theme/templates/init.vm).

Variables:

  • $theme_display
  • $portlet_display
  • $request
  • $css_folder       — -$theme_display.getPathThemeCss()
  • $images_folder —  $theme_display.getPathThemeImages()
  • $javascript_folder –$theme_display.getPathThemeJavaScript()
  • $templates_folder — $theme_display.getPathThemeTemplates()
  • $full_css_path
  • $company
  • $layout  –  Current layout
  • $user
  • $full_templates_path
  • $is_signed_in  — $theme_display.isSignedIn()
  • $current_time
  • $the_year
  • $permissionChecker.isOmniadmin() –> to check Super Admin
  • $dateUtil
  • $escapeTool
  • $propsUtil  -> To get Portal Ext Properties ($propsUtil.get(“propertye-key”))
  • $paramUtil
  • $getterUtil
  • $htmlUtil
  • $portalUtil
  • $portal
  • $prefsPropsUtil
  • $propsUtil
  • $portletURLFactory   ->    Here is sample code to create Portlet URL’s in Velocity templates.                     #set($test_plid = $portalUtil.getPlidFromPortletId($theme_display.getScopeGroupId(), false,                      “test_WAR_testportlet”))                                                                                                                   #set ($test_url = $portletURLFactory.create($request, “test_WAR_testportlet”,                                              $test_plid, “RENDER_PHASE”))                                                                                                                      $test_url.setWindowState(“normal”)                                                                                                        $test_url.setPortletMode(“view”)                                                                                                              $test_url.setParameter(“privateLayout”, “false”)                                                                                      $test_url.setParameter(“cmd”, “basicView”)
  • $stringUtil
  • $unicodeFormatter
  • $validator
  • $arrayUtil
  • $browserSniffer
  • $dateFormats
  • $dateTool
  • $dateUtil
  • $escapeTool
  • $expandoColumnLocalService
  • $expandoRowLocalService
  • $expandoTableLocalService
  • $expandoValueLocalService
  • $httpUtil
  • $imageToken
  • $iteratorTool
  • $languageUtil
  • $unicodeLanguageUtil
  • $localeUtil
  • $randomizer
  • $serviceLocator
  • $sessionClicks
  • $staticFieldGetter
  • $listTool
  • $mathTool
  • $sortTool
  • $numberTool                                                                                                                                                                                                                                                                                                                  Useful code snippets in Liferay theme Velocity templates:
  • Theme. Runtime is used to insert portlet at theme level
    • $theme.runtime(“emailnotification_WAR_kpiemailnotificationportlet_INSTANCE_adfckdkkek”)
  • to check Omni admin
    • #if ($is_signed_in && $permissionChecker.isOmniadmin())
      #dockbar()
      #end
  • To get the cotent based on locale:
    • $languageUtil.get($locale, $the_title, $page.getName($locale))

  • Wednesday 13 September 2017

    Liferay - Build number deployment error

    Many times while deploying portlet you people might have seen following error.


    Build namespace ABC has build number X which is newer than Y.

    Lets first understand why this error is coming . Whenever we build services for our portlets buidl number inside service.properties is getting incremented. And when you deploy portlet Liferay will compare build number available inside service.properties against the build number available inside servicecomponent table. If the build number inside service.properties is less then the one inside servicecomponent table it means you are downgrading your build and your DB changes wont be affected . At that time portal will throw this exception saying

     "Build namespace ABC has build number 3 which is newer than 1". 

    To resolve this problem we need to increase the build number inside service.properties file . For above scenario we need to changes build number to either 3 or greater then 3.

    build.number=4 

    Another solution (not recommended) is you can delete entries for your portlet from servicecomponent table. For more information check this thread on Liferay Forum.

    Popup in Liferay Using Alloy-ui

    Here is the sample example to display pop up in liferay using Alloy -ui

    In pop up body you can display any thing you want

    here in our example we will display simple greeting message in pop up window

    These are Imports:

    <%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
    <%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
    <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
    <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
    <%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
    <%@page import="com.liferay.portal.kernel.language.LanguageUtil"%>
    <%@page import="com.liferay.portal.kernel.portlet.LiferayWindowState"%>
    <liferay-theme:defineObjects/>
    <portlet:defineObjects/>

    Render URL

    <portlet:renderURL var="simpleDialogIframe"
     windowState="<%=LiferayWindowState.POP_UP.toString()%>">
     <portlet:param name="render" value="showPopUp"/>
     </portlet:renderURL>

    In Controller Render()

    @RenderMapping(params = "render=showPopUp")
    public String showPopup(RenderRequest request, RenderResponse response){
    System.out.println("Under Render");
    return showPopUp;
    }

    Button On Click Opening PopUp

     <aui:button name="f1" value="Click" onClick="popUpModel()"/>

    PopUp Script

     <aui:script>
     function popUpModel(){
     var url = "<%=simpleDialogIframe.toString()%>";
       AUI().use('aui-base', 'liferay-util-window', 'aui-io-plugin-deprecated', function(A){
           var popupWidth = 300;
           var customPopUp = Liferay.Util.Window.getWindow({
               dialog:{
                   centered: true,
                   constrain2view: true,
                   modal: true,
                   resizable: false,
                   destroyOnClose: true,
                   destroyOnHide: true,
                   width: popupWidth,
                   height:250,
                   after:{
                       destroy: function(event){
                       }
                   }
               },
               id: "<portlet:namespace/>dialogId"
           }).plug(A.Plugin.DialogIframe,{
               autoLoad: true,
               iframeCssClass: 'dialog-iframe',
               uri: url
           }).render();

           customPopUp.show();
           customPopUp.titleNode.html('<h1>RITHWIK</h1>');

       });
    }

    </aui:script>

    in our example we have created one spring portlet in that i am opening a PopUp in PopUp I am rendering jsp