Posts

Set page permissions to role programmatically

In JSP, // getting list of all public pages List<Layout> pageList = LayoutLocalServiceUtil.getLayouts(themeDisplay.getScopeGroupId(), false); for(Layout pages : pageList){ <input type="checkbox" name='<portlet:namespace/>page' value="<%=pages.getPlid() %>" <%=checked%> /><%=pages.getName() %><%=pages.getPlid()  %> } In Controller, String[] pages = ParamUtil.getParameterValues(request, "page");   for(String page : pages){  long plId = Long.parseLong(page); Layout layout = null; try { layout = LayoutLocalServiceUtil.getLayout(plId); } catch (SystemException e) { }    ResourcePermissionServiceUtil.setIndividualResourcePermissions(themeDisplay.getScopeGroupId(),    themeDisplay.getCompanyId(), Layout.class.getName(), String.valueOf(layout.getPrimaryKey()),    role.getRoleId(), new String[] { ActionKeys.VIEW }); }

Display portlet as popup in theme

Step 1: Open the portal-normal.vm file and write the below code.  portal-normal.vm  #set ($popupUrl = $portletURLFactory.create($request, " login_WAR_portlet ",$page.getPlid(), "RENDER_PHASE")) $popupUrl .setParameter("p_p_state", "exclusive") $popupUrl .setPortletMode("view")    <a href="#" onClick = "showPopup()">Show Popup </a> where ' login_WAR_portlet ' is the portlet name .     Step 2: Write the javascript code for popup in portal-normal.vm or any other .js file. < aui:script > AUI().use('aui-base', 'aui-io-plugin-deprecated', 'liferay-util-window', function(A) { function showPopup(){ var popUpWindow=Liferay.Util.Window.getWindow( { dialog: { centered: true, constrain2view: true, //cssClass: 'yourCSSclassName', modal: true, resizable: false, width: 475 } ...

Liferay Tabs Search container pagination

question_list.jsp  String tabNames = "Active Questions,InActive Questions"; String tabs1= ParamUtil.getString(request,"tabs1", "Active Questions");     Object ob = request.getAttribute("selectedTab");     String value ="Active Questions";     if (ob != null) {     value = (String) ob;     tabs1 = value;     } PortletURL iteratorURL = renderResponse.createRenderURL(); iteratorURL.setParameter("action", "questionlist"); <liferay-ui:tabs    names="<%= tabNames %>"    url="<%= iteratorURL.toString() %>"      param="tabs1"    value="<%=tabs1 %>"   >     <liferay-ui:section>      <c:if test='<%= tabs1.equalsIgnoreCase("Active Questions")%>'>       <liferay-ui:search-container delta="10" emptyResultsMessage="Sorry" iteratorURL="<%...

Date pickers

AUI Date Picker: To Use AUI we need to import: <%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui"%> Then add your input field: <aui:input type="text" name="datepicker" id="datepicker" /> Then add this script: <aui:script> AUI().use('aui-datepicker', function(A) { new A.DatePicker({ trigger : '#<portlet:namespace/>datepicker', popover : { zIndex : 1 } }); }); </aui:script> Liferay UI DatePicker: We need to import: <%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %> Then add your input field: <liferay-ui:input-date formName="dob" yearRangeEnd="2000" yearRangeStart="1950" yearValue="1990" monthValue="3" dayValue="20" dayParam="d1" monthParam="m1" yearParam="y1"/> Jquery DatePicker: To Use Jquery Date Pi...

Currency symbol for all countries

Code to get currency symbol:     Currency currency = null;     Locale locale = null;     String currencySymbol = null;   /*Get List of available countries from liferay country table*/     List<Country> countryCode = CountryServiceUtil.getCountries();         for(Country country:countryCode)     {         try{             locale = new Locale.Builder().setRegion(country.getA2()).build();             currency = Currency.getInstance(locale);                   currencySymbol = currency.getSymbol(locale);               System.out.println("currency symbol is......"+currencySymbol);             } ...

Custom Landing Page Using hook Based On Role

Step 1: Define portal.properties in WEB-INF/liferay-hook.xml. <hook>     <portal-properties>portal.properties</portal-properties> </hook>  Step 2: Go to WEB-INF/src/portal.properties and define the following .  login.events.post=CustomLandingPage Step 3: Go to WEB-INF/src and create new class "CustomLandingPage.java" public class CustomLandingPage extends Action {     @Override     public void run(HttpServletRequest request, HttpServletResponse response) {         try {             String roleName =null;             User users= PortalUtil.getUser(request);             long []roleIds = users.getRoleIds();             LastPath publiclastPath= null;       ...