Pages

Friday 23 May 2014

portal.properties: Load properties from external file

Hi,
        This topic is simple but mandatory for developer to go through with it since this comes with best practices.


1. Include "com.liferay.util.portlet.PortletProps" package into your jsp or in java


2. Make a properties file & put into source folder of your portlet named as portal.properties.


3. put some entries in that file like
                 my_custom_message=this is from your external properties files

4. Now you can fetch the properties by the following way:


  • In Jsp

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
               <portlet:defineObjects />
               <%@ page import="com.liferay.util.portlet.PortletProps" %>
               <%= PortletProps.get("messages.per.page") %>

                



  • In  Java
import com.liferay.mail.util.PortletProps;

PortletProps.get("messages.per.page");



Wednesday 14 May 2014

Display profile pictures of all users in liferay?

Hi,

 Today I am going to show you how you can get Profile picture or Portrait of all users belonging to particular community or organization. Yet the problem sounds little bit easy but this post will save your time to make it correct in single attempt.


Problem :  I want to show a  slider to end user in which logo of all my clients will comes. It will look nice since it is dynamically generated means whenever a user will register & admin has assigned Client(Vendor) role to that particular  user.

Than his/her profile pic or in case of company a logo will automatically append in the existing slider....

Solution:

 1.  Make a simple portlet.

 2.  Put the following code in to your view.jsp


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ page import="com.liferay.portal.service.UserLocalServiceUtil"%>
<%@ page import="com.liferay.portal.model.User"%><%@ page import="java.util.List"%><portlet:defineObjects /><h1> Our Partners</h1><marquee behavior="scroll" direction="left"><%int i= UserLocalServiceUtil.getUsersCount();List<User> user =UserLocalServiceUtil.getUsers(0, i);String imgsrc="/image/user_male_portrait?img_id=";for(int j=1;j<i;j++){%><img src="<%=imgsrc+user.get(j).getPortraitId() %>"/>&#160; &#160; &#160; &#160;<%} %></marquee>


3. Deploy this portlet on liferay server.

4. Put ity on desire page.

5. It will show a slider(marquee) with profile pic of all users.6. Here is the output









Please keep sharing.... what you learn.


:)