Posts

Showing posts with the label Liferay

Change Liferay Default User Portrait

Step 1: Add the below given properties in portal-ext.properties file. portal-ext.properties file location : %LIFERAY_HOME%\tomcat-7.0.62\webapps\ROOT\WEB-INF\classes If there no file exists with this name, please create this. And then add below lines. image.default.user.female.portrait=com/images/user_female_portrait.png image.default.user.male.portrait=com/images/user_male_portrait.png Step 2: Add the default custom image under below given path %LIFERAY_HOME%\tomcat-7.0.62\webapps\ROOT\WEB-INF\classes\com\images\ Step 3: Restart the server Enjoy !!!!

Localization in liferay.

Liferay support several localization.You can easily localize your application to support more than one language. You can override existing language key and also add language key in hook. Configure your hook as below. <?xml version="1.0"?> <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd"> <hook>     <portal-properties>portal.properties</portal-properties>     <language-properties>content/Language_en.properties</language-properties>     <language-properties>content/Language_nl.properties</language-properties>     <language-properties>content/Language_pt.properties</language-properties> </hook> Here above hook show three language(nl,pt and en) support. Add above three language files in src/content folder. You can also say in hook, how many languages support by your application. For...

Cosuming Liferay JSON Web Services

In liferay you can write json web service  easily. You can also consume those web service from other client such in java httpclient, javascript(like ajax jquery), dukescript and other client . For example you have a portlet name test-portlet and you write a json webservice as below:     @JSONWebService(value = "testService", method = "POST")     public JSONObject testService(String test) throws SystemException {         JSONObject result = JSONFactoryUtil.createJSONObject();         result.put("test", test);         return result;     } For consuming this service from several clients you can follow below steps: 1. In java client Here you can use jersy.  Client code given below:        Client    client = ClientBuilder.newClient();         ...

How to find the companyId in Liferay.

In liferay many services require comapanyId. In lifeay company means portal instance. You can find this easily. Get comapanyId in code: PortalUtil.getDefaultCompanyId(); this give you default companyId. PortalUtil.getCompanyId(request); here request means HttpServletRequest. PortalUtil.getCompanyId(portletRequest);here portletRequest means any portletRequest(Render,Action or Resource).  ThemeDisplay themeDisplay=(ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);themeDisplay.getCompanyId();  Get current companyId from specific thread local storage by:             CompanyThreadLocal.getCompanyId(); Get comapanyId manually: To find the company ID (portal instance ID), follow these steps: 1/ Sign into portal as admin user 2/ Navigation the Portal Instances admin page Navigation Path is "Dockbar > Admin > Control Panel > (Configuration) Portal Instances 3/ Review first column  "Instance ID" The i...

How to integrate openoffice and liferay for document conversion.

Follow below steps: 1. First to download openoffice open terminal and execute. wget http://freefr.dl.sourceforge.net/project/openofficeorg.mirror/4.0.0/binaries/en-US/Apache_OpenOffice_4.0.0_Linux_x86-64_install-deb_en-US.tar.gz 2. Go to download folder. execute  tar -xvzf Apache_OpenOffice_4.0.0_Linux_x86-64_install-deb_en-US.tar.gz 3. Install the .deb files by typing sudo dpkg -i *.deb 4. Got to /opt/openoffice4/program$ execute sudo sh soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard & 5. Go to liferay control panel>server administrator>external services and then enable open office with port 8100 Enjoy..

Liferay code to check is User login.

There several way to check user isLogin in liferay. 1. In Java code: From ThemeDisplay object ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); boolean signedIn = themeDisplay.isSignedIn(); 2. In Jsp file: <%@ taglib uri = "http://liferay.com/tld/theme" prefix = "liferay-theme" %> <liferay-theme:defineObjects />  < c:choose >   < c:when test = " <%= themeDisplay . isSignedIn() % > " >   <c:when >  < c:otherwise >  <c:otherwise > </ c:choose > 3. In vm file : if ($is_signed_in)  4. In Web content template: #set ($isSignedIn = $request.get("remote-user")) #if ($isSignedIn!='') #end   5. In javascript file:  <script >   $(document).ready(function(){          if((Liferay.ThemeDisplay.isSignedIn())){               ...

Sample code for geting different url in liferay.

Liferay developers often need to find different from render/servlet request. Here below i share some code to get different url in liferay Sample code:         HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(request);         String currentCompleteUrl = PortalUtil.getCurrentCompleteURL(servletRequest);         try {                         String renderCurrentURL =    PortalUtil.getCurrentURL(request);             String servletRequestCurrentURL = PortalUtil.getCurrentURL(servletRequest);             String canonicalURL    = PortalUtil.getCanonicalURL(currentCompleteUrl, themeDisplay, themeDisplay.getLayout());          ...

How to configure/integrate ldap with liferay.

Image
Its very easy to integrate/configure ldap with liferay. To do this you need below: 1. LDAP server(to manage user, groups and authentication) Follow below link to install Ubuntu in linux .. http://www.unixmen.com/install-and-configure-openldap-in-ubuntu-15-04-and-debian-8/   2. Login liferay as admin and go to control panel> got portal settings > authintication and then configure as below: Export Mapping: Users DN = dc=example,dc=com User Default Object Classes = top,person,inetOrgPerson,organizationalPerson User Mapping: Screen Name =cn Email Address =mail Password =userPassword First Name =givenName Last Name =sn Connection: Base Provider URL=ldap://localhost:389 Base DN=dc=example,dc=com Principal =cn=admin,dc=example,dc=com Credentials = ldap admin pass Users: Authentication Search Filter=(mail=@email_address@) Import Search Filter=(objectClass=person) Finally change the below properties: ldap.auth.password.encrypt...

How to change Portrait/Profile photo in liferay programitically.

Sometime liferay developer need to change profile/portrait photo programmatically . Here i want to share my experience. Create portlet action url and method as below: In jsp file create action url: <script type="text/javascript" src="<%= request.getContextPath()%>/js/jasny-bootstrap.min.js"></script> <link rel="stylesheet" href="<%= request.getContextPath()%>/css/jasny-bootstrap.min.css"> <portlet:actionURL name="updateProfile" var="updateProfileURL" windowState="normal"/> <form action="<%=updateProfileURL %>" method="post" enctype="multipart/form-data" id='<portlet:namespace/>updateProfile'>                 <input name="<portlet:namespace/>userEmail" id='<portlet:namespace/>userEmail' type="hidden" value="" />                 <div class="col-xs-12 col...

Liferay enviorment set up step by step.

Image
1. Download liferay-portal, liferay-plugin from github Portal URL:https://github.com/liferay/liferay-portal Plugin URL:https://github.com/liferay/liferay-plugins You can download as zip or git clone from here. 2. Go to downloaded liferay-portal directory and run the command "ant all" Before this install java and ant. And install ecj. For this follow the below link: http://tariqliferay.blogspot.com/2015/02/liferay-builds-with-ecj-compilertricks.html After some times BUILD FAILED and show, If you already have Tomcat installed, make sure the property "${app.server.tomcat.dir}" points to your Tomcat installation. Please run the below command "ant -buildfile build-dist.xml unzip-tomcat" And then again run the command "ant all" 3. This will be created a folder named "bundle" in the same directory. 4. Go to bundle folder and there should be appear apache tomcat directory. 5. Go to bin folder and run the command ...

Service Script for LifeRay on Ubuntu

Liferay developer need write script to start and stop liferay as service. In my projects production and test server management i need this, and after spending few times  i got this. Here below i share my experience. The script code given below. #!/bin/bash # # tomcat     This shell script takes care of starting and stopping Tomcat # # chkconfig: - 80 20 # ### BEGIN INIT INFO # Provides: tomcat # Required-Start: $network $syslog # Required-Stop: $network $syslog # Default-Start: # Default-Stop: # Short-Description: start and stop tomcat ### END INIT INFO #TOMCAT_HOME="/home/tariq/projects/projects/bundles/tomcat-7.0.42" TOMCAT_HOME="Home of your liferay tomcat" SHUTDOWN_WAIT=45 tomcat_pid() { #filter running process, here you can add extra filter criteria by adding | grep #criteria text     echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'` } start() {     pid=$(...

Ajax form submit in liferay.

Sometimes liferay developer need to submit form in ajax. Here below i share my experience for on ajax form submit in liferay. You can download source code from here.. Below the view.jsp: <%-- --%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %> <%@ taglib uri="http://liferay.com/tld/ddm" prefix="liferay-ddm" %> <%@ taglib uri="http://liferay.c...

How to read and write properties files in liferay

Liferay developer sometimes need to read and write properties files. 1.     For golobal configurations one can put properties valuse on portal.properties     You can acheive this by overwrite portal.properties using Liferay Hook.     As below:      <?xml version="1.0"?>     <!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">     <hook>         <portal-properties>portal.properties</portal-properties>     </hook>     and then write your requird key values in this file.     Below sample key values:      default.landing.page.path=/web/guest/home     company.default.home.url=/web/guest/home         To read golobal portal properties file you can use liferay com.liferay...

Disable default error and sucess message in liferay portlet.

Follow the below step to disable default error and success message in liferay portlet: Step 1: Add the below code in portlet.xml <init-param>             <name>add-process-action-success-action</name>             <value>false</value> </init-param> Before <expiration-cache>0</expiration-cache> Step 2: Add the below code in portlet action method PortletConfig portletConfig = (PortletConfig)actionRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);             LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig;             SessionMessages.add(actionRequest, liferayPortletConfig.getPortletId() + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);            ...

Custom Login Portet In Liferay.

Sometimes liferay developer needs create custom login/signin protlet for their requirement. Here share my experience how one can create  custom login portlet in liferay. Dowload the portlet form github Step 1: jsp file >>> Replace the view.jsp file with the below code. <%-- /** * tariqliferay.blogspot.com */ --%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %> <%@ taglib uri="http://liferay.com/tld/ddm" prefix="liferay-ddm" %> <%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %> <%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %> <%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay...