Pages

Monday 29 September 2014

Disable Built-in portlet (Default) in Liferay

Hi Friends,

As we know liferay comes with bundle of 60+ App(portlet) built in with default installation.
 Like

  • Asset Publisher
  • Blog
  • Blog Display
  • Navigation
  • Tag
  • Breadcrumb
WE can use them as per requirement.
Still many of portlet are not useful when we designing for real application. Therefore It is recommended that we have to disable them so that these portlet will not appear in App section as well as control panel.

When we disable any portlet JVM does not load the classes related to that particular portlet so we can also optimized the Liferay portal by disabling the unused portlet.

To disable a built-in portlet we have two options.

Using lifeary-portlet.xml


1. Directly modified the liferay-portlet.xml file located at following path

<liferay installation><tomcat-7.0.42 or your app server>\webapps\ROOT\WEB-INF\

2. find the portlet with id if you know or by name as well
for example I want to disable the liferay search portlet then we know its id is 2

3. you will get a block like this



<portlet>
<portlet-name>2</portlet-name>
<icon>/html/icons/my_account.png</icon>
<struts-path>my_account</struts-path>
<portlet-url-class>com.liferay.portal.struts.StrutsActionPortletURL</portlet-url-class>
<control-panel-entry-category>my</control-panel-entry-category>
<control-panel-entry-weight>1.0</control-panel-entry-weight>
<preferences-owned-by-group>true</preferences-owned-by-group>
<use-default-template>false</use-default-template>
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>
<render-weight>50</render-weight>
<header-portlet-css>/html/portlet/users_admin/css/main.css</header-portlet-css>
<footer-portlet-javascript>/html/portlet/users_admin/js/main.js</footer-portlet-javascript>
<css-class-wrapper>portlet-users-admin</css-class-wrapper>
<add-default-resource>true</add-default-resource>
<system>true</system>

</portlet>

4. now at the end of this block just before closing of portlet tag </portlet> put the following line,

<include>false</include>

and the above code will look like this after changes.



<portlet>
<portlet-name>2</portlet-name>
<icon>/html/icons/my_account.png</icon>
<struts-path>my_account</struts-path>
<portlet-url-class>com.liferay.portal.struts.StrutsActionPortletURL</portlet-url-class>
<control-panel-entry-category>my</control-panel-entry-category>
<control-panel-entry-weight>1.0</control-panel-entry-weight>
<preferences-owned-by-group>true</preferences-owned-by-group>
<use-default-template>false</use-default-template>
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>
<render-weight>50</render-weight>
<header-portlet-css>/html/portlet/users_admin/css/main.css</header-portlet-css>
<footer-portlet-javascript>/html/portlet/users_admin/js/main.js</footer-portlet-javascript>
<css-class-wrapper>portlet-users-admin</css-class-wrapper>
<add-default-resource>true</add-default-resource>
<system>true</system>
               <include>false</include>

</portlet>



5. save the file & restart the server just it.

Using lifeary-portlet-ext.xml


1. create a ext plugin project.

go to
docroot/WEB-INF/ext-web/docroot/WEB-INF/

2.
open liferay-portlet.xml file



& place the below code before closing  </liferay-portlet-app>

<portlet>
<portlet-name>2</portlet-name>
<icon>/html/icons/my_account.png</icon>
<struts-path>my_account</struts-path>
<portlet-url-class>com.liferay.portal.struts.StrutsActionPortletURL</portlet-url-class>
<control-panel-entry-category>my</control-panel-entry-category>
<control-panel-entry-weight>1.0</control-panel-entry-weight>
<preferences-owned-by-group>true</preferences-owned-by-group>
<use-default-template>false</use-default-template>
<private-request-attributes>false</private-request-attributes>
<private-session-attributes>false</private-session-attributes>
<render-weight>50</render-weight>
<header-portlet-css>/html/portlet/users_admin/css/main.css</header-portlet-css>
<footer-portlet-javascript>/html/portlet/users_admin/js/main.js</footer-portlet-javascript>
<css-class-wrapper>portlet-users-admin</css-class-wrapper>
<add-default-resource>true</add-default-resource>
<system>true</system>
               <include>false</include>

</portlet>

3.
Deploy the war in deploy folder of your app server.

4. since its a ext plugin so you will have to restart the server after deployment.



Please let me know if you have any query. 


Keep sharing, what you learn... :)





Tuesday 15 July 2014

Run PHP application inside Liferay server

yes, as all we know Liferay supports almost all scripting language like ruby & PHP.
To run PHP application we will have to follow these steps.

1. Try to make a dummy PHP initially. So that in first integration testing it will easy to debug.

2. Create a new txt file with below content.

<?php
$first_number = 10;
$second_number = 20;
$sum_total = $first_number + $second_number;
$direct_text = 'The two variables added together = ';
print ($direct_text . $sum_total);
?>


save the file from .txt to .php extension.


3. now right click on this file & zip that file say myphp.zip

4. Like all .war file you just have to but this zip file inside deploy folder of liferay server.

5. Either it will taken care by hot deploy or you can restart the server.

6. Now login into liferay with admin role.

7. Goto add bottom a list of available portlet will appear.

8. You will see myphp drag & drop this to your page that it.

9. Your PHP portlet now in action.

The two variables added together = 30


Keep Sharing...
                   what you learn.......



Problem in Liferay 6.2 CE Installation




I have noticed that Liferay 6.2 CE standard version doesn't come with JRE inside tomcat.
So when you try to start the liferay server on windows the terminal will close by its own.
& in linux you will get JRE not found like error.

The main cause of this is that we dont have jre inside Tomcat bundle in liferay.


  • To resolve the same issue either download a fresh bundle with JRE included.

download from here

  • Or you can copy & paste JRE folder inside your liferay 6.2 tomcat from the last liferay 6.1 version. 


Please let me know if you have any query. 


Keep sharing, what you learn... :)




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.


:)


Thursday 6 February 2014

Liferay Database Migration

Hi friends,
              From liferay 6.1 it becomes very easy to migrate database of liferay from  its default hqDB to your desired database life Mysql, MSSQl, PostSql from control panel. In this post I will tell you how to achieve this both from control panel & by using portal-ext.properties file.



From Control panel.

1. login as admin in your liferay portal.
2.Go to control panel.
3. Chosse  from right hand panel--->server-server administrator--->Data Migration tab
4. be sure you have connector .jar for your particular jar. Mysql.jar is already placed in liferay portal so no need to do any staff.
put driver class as--->com.mysql.jdbc.Driver
JDBC url--->jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
user-->username of lportal
password-->password of database
than click on execute.


that it the portal will restart by its own & migrate all data in your database.


From portal-ext.properties file.

1.Open location
liferay root->tomcat-->webapp-->root-->WEB-INF-->classes
2.create a new file portal-ext.properties here
and paste this content as it as for my sql.


jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=password




above explaination

first line is used for driver class.

second line is used for giving the url where database server is running here i have used localhost after that database name which you want to use for migration.(lportal in my case)

third line used for username of database which have all permissions.

fourth line contains password of that user.


after that save this file & restart the liferay server & you will see the tables in your own database.

please download the portal-ext.properties file from here if you have any trouble.