Liferay"

From Documentation
 
(19 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
= Setting up Liferay =
 
= Setting up Liferay =
  
There are several ways you can set up Lifetray, one is to goto [http://www.liferay.com Liferay] and download the pre-bundled liferay tomcat bundled. This is the easiest method, but of course not ideal if you have a pre-existing tomcat server.
+
There are several ways in which an application can be set up within Liferay, the first one being to simply go to [http://www.liferay.com Liferay] and download the pre-bundled liferay tomcat bundle (other app server bundles are also available but experiences indicate that other ones might be trickier to begin with as the configuration is usually more lengthy), however, this option is not ideal if the user already have an existing tomcat server.
  
If you have a tomcat server already and don't particularly feel like deploying another one, you can download the liferay war. Liferay's installation typically removes the ROOT from the server, but I don't particularly like doing that so I'll explain with out having to loose your root
+
If the user already has a tomcat server on hand and does not particularly feel like deploying another one, the second option would be to download "liferay war". Typically, Liferay's installation removes the ROOT folder from the server, to avoid this situation, please stick to the following steps closely.
  
* First, if you don't have tomcat, download and install the latest stable tomcat on the OS of your pleasure (you can try other app servers but experience has taught me other ones might be trickier to begin with as the configuration is usually more lengthy).  
+
* Download the non-bundled liferay war (Liferay Portal Professional 4.2.1 WAR) from [http://www.liferay.com Liferay]
  
* Next download the non-bundled liferay war (Liferay Portal Professional 4.2.1 WAR) from [http://www.liferay.com Liferay]
+
* Download the additional file called Liferay Portal 4.2.1 Dependencies, and unzip it to shared/lib
  
* Also download the additional file called Liferay Portal 4.2.1 Dependencies, and unzip it to shared/lib
+
* In order to keep the ROOT folder, extract the contents of the war into a folder, call it 'myportal' for instance.
  
* In order to keep your ROOT you'll need to extract the contents of the war into a folder, call it 'myportal' fo instance.
+
* Under the WEB-INF folder, create a 'classes' folder, in this folder create a file called 'portal-ext.properties', and in this file place the following (note that users may of course change the portal.ctx and/or the lucene and jackrabbit directory depending on later configurations):
 
 
* Under the WEB-INF folder create a 'classes' folder, in this folder create a file called 'portal-ext.properties', in the file put the following (note you may of course change the portal.ctx and/or the lucene and jackrabbit directory depending on your later configurations):
 
  
 
<source lang="text">
 
<source lang="text">
Line 27: Line 25:
 
</source>
 
</source>
  
* Go back into the WEB-INF folder and edit the web.xml change the root_path to have a param value of '/myportal', so the top of the web.xml will look as follows:
+
* Go back to the WEB-INF folder and edit the web.xml - change the root_path to have a param value of '/myportal', so that the top of the web.xml will look as follows:
  
 
<source lang="xml">
 
<source lang="xml">
Line 51: Line 49:
 
</source>
 
</source>
  
* Now go into the META-INF folder and add a file called 'context.xml' and add the following (configure this to your own spefics just make sure the context path attribute is '/myportal', if you don't use mysql database and just want liferay to use hSQLdb, just strip out the first Resource element):
+
* Now go into the META-INF folder and add a file called 'context.xml' and add the following (configure this according to own specifics, just make sure that the context path attribute is '/myportal', if the user does not use mysql database and wants liferay to use hSQLdb, strip out the first Resource element):
  
 
<source lang="xml">
 
<source lang="xml">
Line 85: Line 83:
 
</source>
 
</source>
  
* Now for the real trick, liferay 4.2 has a small bug when you change the context to something other than the ROOT. In the folder html/portal you will find a file called load_render_portlet.jsp, open the file up and go to line 55-56should look as follows:
+
* Now for the real trick, liferay 4.2 has a small bug when changing the context to something other than the ROOT. In the folder html/portal, find a file called load_render_portlet.jsp, open the file up and go to line 55-56 and it should look like the following:
  
 
<source lang="javascript">
 
<source lang="javascript">
Line 99: Line 97:
 
</source>
 
</source>
  
Ok I'm sure there is a better way of doing that, but I'd rather let the liferay boys do that themselves.
 
  
* If you wish to use mySQL, you'll need to modify the context.xml to your own configurations, you'll also need to download the liferay-mysql script file and run it against your database.
+
* If the user wishes to use mySQL, modify the context.xml to the user's own configurations, the user will also need to download the liferay-mysql script file and run it against the user's database.
  
* Now on you root folder (i.e. C:\ for windows, / for UNIX/LINUX) you'll need to create a 'home' folder (if it doesn't exist) and in that a 'liferay' folder. Make sure tomcat has permission to modify the folder.
+
* Now, in the ROOT folder (i.e. C:\ for windows, / for UNIX/LINUX), create a 'home' folder (if it doesn't already exist) and in that folder, create a 'liferay' folder. Make sure tomcat has permission to modify the folder.
  
* Now all you need do is re zip the folder and rename the zip file to myportal.war, drop it into tomcat's webapps deploy directory and (hopefully) you have a working liferay portal.
+
* Now, re zip the folder and rename the zip file to myportal.war, drop it into tomcat's webapps deploy directory and (hopefully) a working liferay portal will appear.
  
 
= Deploying a ZK portlet =
 
= Deploying a ZK portlet =
  
Here I'll assume you are familiar with and have created a ZK war.
+
Here, this guide assumes that users are familiar with and have created a ZK war.
  
* First, you need to tell liferay about your portlet so create a class that looks like this:
+
* First, in order to tell liferay about the portlet, create a class that looks like this:
  
 
<source lang="java">
 
<source lang="java">
Line 222: Line 219:
 
</source>
 
</source>
  
* Next in your WEB-INF create a 'liferay-display.xml' file that looks as follows:
+
* Next, create a 'liferay-display.xml' file that looks like the following in WEB-INF:
  
 
<source lang="xml">
 
<source lang="xml">
Line 235: Line 232:
 
</source>
 
</source>
  
* Now also in the WEB-INF create a file called 'liferay-portlet.xml' that looks as follows:
+
* Now, also in the WEB-INF, create a file called 'liferay-portlet.xml' that looks like the following:
  
 
<source lang="xml">
 
<source lang="xml">
Line 265: Line 262:
 
</source>
 
</source>
  
*''' Liferay 5.2.* ''': Liferay 5.2 adds cache filters to your web.xml when you deploy on the liferay server. These will block the zk javascript (*.js) communication. To make it work you have to add the property "speed-filters-enabled=false" in the liferay-plugin-package.properties file in the WEB-INF directory.
+
*''' Liferay 5.2.* ''': Liferay 5.2 adds cache filters to users' web.xml when deployed on the liferay server. These, however, blocks the zk javascript (*.js) communication. To avoid this, add the property "speed-filters-enabled=false" in the liferay-plugin-package.properties file in the WEB-INF directory.
  
  
Line 306: Line 303:
 
</source>
 
</source>
  
* You'll note the /view.zul reference in this file is the 'index' file of the portlet, also note through out all these file I have referenced 'portletone', you'll need to change this to the name of your war.
+
* Note that the /view.zul reference in this file is the 'index' file of the portlet, and all these files have been referenced as 'portletone', please change this as the name of the war file.
  
* Finally at the top of your web.xml file after <web-app> add the following (followed by the typical ZK stuff):
+
* Finally, at the top of the web.xml file after <web-app> add the following (followed by the typical ZK stuff):
  
 
<source lang="xml">
 
<source lang="xml">
Line 327: Line 324:
 
</source>
 
</source>
  
BJaouad
+
Notice that company_id is left as liferay.com.This is because changing the value would also mean digging around the liferay database and it would be hard to find all the places to modify the values.  
 
 
You'll notice I left the company_id as liferay.com. I've left it like this because changing the value also means digging around the liferay database, it's not that hard to find all the place to modify the value, so if you do, your on your own.
 
  
 
* Deploy the resulting war into /home/liferay/deploy directory,  
 
* Deploy the resulting war into /home/liferay/deploy directory,  
  
* Access and sign in to your portal, click on 'Add Content' link, under the category 'Test' add 'Sample JSP Portlet'.
+
* Access and sign in to the user's portal, click on 'Add Content' link, under the category 'Test' add 'Sample JSP Portlet'.
  
Hey presto, one portal with ZK portlet
 
  
 
== Running ZK 5 with Liferay 5.2  ==
 
== Running ZK 5 with Liferay 5.2  ==
Line 343: Line 337:
 
'''Steps'''
 
'''Steps'''
 
<br/>
 
<br/>
1.Download Liferay bundled with Tomcat (we use liferay-portal-tomcat-6.0-5.2.1 here)
+
1.Download Liferay-Tomcat bundle (this example uses liferay-portal-tomcat-6.0-5.2.1)
 
<br/>
 
<br/>
 
2.Create a ZK 5 Project
 
2.Create a ZK 5 Project
Line 349: Line 343:
  
 
3.
 
3.
Inside WEB-INF folder, Liferay need four xml file for setting.  
+
Inside the WEB-INF folder, in order to run the ZK application, set up the following four xml files in Liferay.  
  
In order to integrate with ZK, pay attention to '''portlet.xml''', we use setting:
+
In order to integrate Liferay with ZK, add the following settings to the '''portlet.xml''' setting:
 
*'''<portlet-class>org.zkoss.zk.ui.http.DHtmlLayoutPortlet</portlet-class>'''
 
*'''<portlet-class>org.zkoss.zk.ui.http.DHtmlLayoutPortlet</portlet-class>'''
 
*And create a '''zk_page''' called '''hello.zul'''  
 
*And create a '''zk_page''' called '''hello.zul'''  
Line 477: Line 471:
 
Reason: under IE, using Liferay with ZK will cause HTML Parsing Error (KB927917)
 
Reason: under IE, using Liferay with ZK will cause HTML Parsing Error (KB927917)
 
<br/>
 
<br/>
Solution: we could use '''jQueryPatch''' and set appropriate '''time delay value''' for browser.
+
Solution: use '''jQueryPatch''' and set appropriate '''time delay value''' for browser.
 
<br/>
 
<br/>
 
*zk.xml
 
*zk.xml
Line 501: Line 495:
 
5. Export war file
 
5. Export war file
 
<br/>
 
<br/>
Export war file called '''DEPLOY_TO__HelloZK.war''', and put  this war file under '''deploy''' folder
+
Export a war file called '''DEPLOY_TO__HelloZK.war''', and put  this war file under the '''deploy''' folder
  
In Liferay, it will deploy war file by it's name, when we use the name '''DEPLOY_TO__HelloZK.war''', liferay will deploy this war file to folder '''HelloZK'''
+
Liferay deploys war files by its name, when the name '''DEPLOY_TO__HelloZK.war''' is used, liferay will deploy this war file to folder '''HelloZK'''
  
  
Line 511: Line 505:
  
 
== Running ZK 5 with Liferay 6  ==
 
== Running ZK 5 with Liferay 6  ==
Version: Liferay: 6.0.4 and ZK 5
+
Version: Liferay: 6.0+ and ZK 5
  
 
Steps
 
Steps
Line 519: Line 513:
 
2. Create a ZK 5 Project  
 
2. Create a ZK 5 Project  
  
3. Inside WEB-INF folder, Liferay need four xml file for setting. And zk.xml need to add setting '''JQueryRenderCachedPatch'''
+
3. Inside the WEB-INF folder, in order to run ZK, users need to add four xml files to set up Liferay.  
 +
'''JQueryRenderCachedPatch''' needs to be added to the zk.xml setting
  
  
The main difference between 5.2 and Liferay 6.0 is the '''liferay-portlet.xml''' and '''zk.xml'''
+
The main difference between Liferay 5.2 and Liferay 6.0 is '''liferay-portlet.xml''' and '''zk.xml'''
 +
 
 +
*web.xml:
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
 
 +
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 +
<display-name>HelloZK2</display-name>
 +
<listener>
 +
<description>Used to cleanup when a session is destroyed</description>
 +
<display-name>ZK Session cleaner</display-name>
 +
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
 +
</listener>
 +
<servlet>
 +
<description>The ZK loader for ZUML pages</description>
 +
<servlet-name>zkLoader</servlet-name>
 +
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
 +
<init-param>
 +
<param-name>update-uri</param-name>
 +
<param-value>/zkau</param-value>
 +
</init-param>
 +
<load-on-startup>1</load-on-startup>
 +
</servlet>
 +
<servlet>
 +
<description>The asynchronous update engine for ZK</description>
 +
<servlet-name>auEngine</servlet-name>
 +
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
 +
</servlet>
 +
<servlet-mapping>
 +
<servlet-name>zkLoader</servlet-name>
 +
<url-pattern>*.zul</url-pattern>
 +
</servlet-mapping>
 +
<servlet-mapping>
 +
<servlet-name>zkLoader</servlet-name>
 +
<url-pattern>*.zhtml</url-pattern>
 +
</servlet-mapping>
 +
<servlet-mapping>
 +
<servlet-name>auEngine</servlet-name>
 +
<url-pattern>/zkau/*</url-pattern>
 +
</servlet-mapping>
 +
<session-config>
 +
<session-timeout>60</session-timeout>
 +
</session-config>
 +
<welcome-file-list>
 +
<welcome-file>index.zul</welcome-file>
 +
<welcome-file>index.zhtml</welcome-file>
 +
<welcome-file>index.html</welcome-file>
 +
<welcome-file>index.htm</welcome-file>
 +
</welcome-file-list>
 +
</web-app>
 +
</source>
  
 
*zk.xml:  
 
*zk.xml:  
use '''JQueryRenderCachedPatch'''
+
*use '''JQueryRenderCachedPatch'''
<source lang="javascript">
+
<source lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<zk>
 
<zk>
Line 532: Line 577:
 
<name>org.zkoss.zk.portlet.PageRenderPatch.class</name>
 
<name>org.zkoss.zk.portlet.PageRenderPatch.class</name>
 
<value>org.zkoss.zkplus.liferay.JQueryRenderCachedPatch</value>
 
<value>org.zkoss.zkplus.liferay.JQueryRenderCachedPatch</value>
 +
</library-property>
 +
<library-property>
 +
<name>org.zkoss.zkplus.liferary.jQueryPatch</name>
 +
<value>1500</value>
 +
</library-property>
 +
</zk>
 +
</source>
 +
[since 5.0.11]
 +
*use '''NonRootContextJQueryRenderPatch''' instead of '''JQueryRenderCachedPatch''' if the home page of Liferay is not under the root(/) path
 +
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<zk>
 +
<library-property>
 +
<name>org.zkoss.zk.portlet.PageRenderPatch.class</name>
 +
<value>org.zkoss.zkplus.liferay.NonRootContextJQueryRenderPatch</value>
 
</library-property>
 
</library-property>
 
<library-property>
 
<library-property>
Line 541: Line 602:
  
 
*liferay-portlet.xml:
 
*liferay-portlet.xml:
add this setting '''<header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>'''
+
add this to the setting '''<header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>'''
<source lang="javascript">
+
  [Since 7.0.3]
 +
* You don't need '''<header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>''' setting any more.
 +
<source lang="xml">
 
<liferay-portlet-app>
 
<liferay-portlet-app>
 
<portlet>
 
<portlet>
 
<portlet-name>HelloZK2</portlet-name>
 
<portlet-name>HelloZK2</portlet-name>
 +
<!-- don't need this since ZK 7.0.3 -->
 
<header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>
 
<header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>
 
</portlet>
 
</portlet>
Line 564: Line 628:
  
 
*liferay-display.xml
 
*liferay-display.xml
<source lang="javascript">
+
<source lang="xml">
 
<?xml version="1.0"?>
 
<?xml version="1.0"?>
 
<!DOCTYPE display PUBLIC "-//Liferay//DTD DISPLAY 2.0.0//EN" "http://www.liferay.com/dtd/liferay-display_2_0_0.dtd">
 
<!DOCTYPE display PUBLIC "-//Liferay//DTD DISPLAY 2.0.0//EN" "http://www.liferay.com/dtd/liferay-display_2_0_0.dtd">
Line 576: Line 640:
  
 
*liferay-plugin-package.xml
 
*liferay-plugin-package.xml
<source lang="javascript">
+
<source lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<!DOCTYPE plugin-package PUBLIC "-//Liferay//DTD Plugin Package 4.3.6//EN" "http://www.liferay.com/dtd/liferay-plugin-package_4_3_0.dtd">
 
<!DOCTYPE plugin-package PUBLIC "-//Liferay//DTD Plugin Package 4.3.6//EN" "http://www.liferay.com/dtd/liferay-plugin-package_4_3_0.dtd">
Line 607: Line 671:
  
 
*portlet.xml
 
*portlet.xml
<source lang="javascript">
+
<source lang="xml">
 
<?xml version="1.0" encoding="UTF-8"?>
 
<?xml version="1.0" encoding="UTF-8"?>
 
<portlet-app version="1.0"
 
<portlet-app version="1.0"
Line 648: Line 712:
 
</source>
 
</source>
  
Please download the following war file for the detail setting
+
Please download the following war file to view this example in detail
  
 
'''Download'''
 
'''Download'''

Latest revision as of 08:53, 18 March 2015


Setting up Liferay

There are several ways in which an application can be set up within Liferay, the first one being to simply go to Liferay and download the pre-bundled liferay tomcat bundle (other app server bundles are also available but experiences indicate that other ones might be trickier to begin with as the configuration is usually more lengthy), however, this option is not ideal if the user already have an existing tomcat server.

If the user already has a tomcat server on hand and does not particularly feel like deploying another one, the second option would be to download "liferay war". Typically, Liferay's installation removes the ROOT folder from the server, to avoid this situation, please stick to the following steps closely.

  • Download the non-bundled liferay war (Liferay Portal Professional 4.2.1 WAR) from Liferay
  • Download the additional file called Liferay Portal 4.2.1 Dependencies, and unzip it to shared/lib
  • In order to keep the ROOT folder, extract the contents of the war into a folder, call it 'myportal' for instance.
  • Under the WEB-INF folder, create a 'classes' folder, in this folder create a file called 'portal-ext.properties', and in this file place the following (note that users may of course change the portal.ctx and/or the lucene and jackrabbit directory depending on later configurations):
portal.release=professional
portal.ctx=/myportal
auto.deploy.dest.dir=../webapps
portal.instances=1
lucene.dir=C:/home/liferay/lucene
jcr.jackrabbit.repository.root=C:/home/liferay/jackrabbit
omniadmin.users=
  • Go back to the WEB-INF folder and edit the web.xml - change the root_path to have a param value of '/myportal', so that the top of the web.xml will look as follows:
<?xml version="1.0"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
	<context-param>
		<param-name>company_id</param-name>
		<param-value>liferay.com</param-value>
	</context-param>
	<context-param>
		<param-name>root_path</param-name>
		<param-value>/myportal</param-value>
	</context-param>
	<filter>
		<filter-name>Auto Login Filter</filter-name>
		<filter-class>com.liferay.portal.servlet.filters.autologin.AutoLoginFilter</filter-class>
	</filter>
.
.
.
  • Now go into the META-INF folder and add a file called 'context.xml' and add the following (configure this according to own specifics, just make sure that the context path attribute is '/myportal', if the user does not use mysql database and wants liferay to use hSQLdb, strip out the first Resource element):
<Context path="/myportal" reloadable="true" >
    <Resource
        name="jdbc/LiferayPool"
        auth="Container"
        type="javax.sql.DataSource"
        driverClassName="com.mysql.jdbc.Driver"
	  url="jdbc:mysql://localhost/lportal?useUnicode=true&amp;characterEncoding=UTF-8"
        username="liferay"
        password="yarefil"
        maxActive="100"
        maxIdle="30"
        maxWait="10000"
    />
    <Resource
                name="mail/MailSession"
                auth="Container"
                type="javax.mail.Session"
                mail.transport.protocol="smtp"
                mail.smtp.host="localhost"
    />
    <Realm 
                className="org.apache.catalina.realm.JAASRealm"
                appName="PortalRealm"
                userClassNames="com.liferay.portal.security.jaas.PortalPrincipal"
                roleClassNames="com.liferay.portal.security.jaas.PortalRole"
                debug="99"
                useContextClassLoader="false"
    />
</Context>
  • Now for the real trick, liferay 4.2 has a small bug when changing the context to something other than the ROOT. In the folder html/portal, find a file called load_render_portlet.jsp, open the file up and go to line 55-56 and it should look like the following:
	function <%= namespace %>loadPortlet() {
		var path = "/c/portal/render_portlet";

however it should look as follows:

	function <%= namespace %>loadPortlet() {
		var path = "/myportal/c/portal/render_portlet";


  • If the user wishes to use mySQL, modify the context.xml to the user's own configurations, the user will also need to download the liferay-mysql script file and run it against the user's database.
  • Now, in the ROOT folder (i.e. C:\ for windows, / for UNIX/LINUX), create a 'home' folder (if it doesn't already exist) and in that folder, create a 'liferay' folder. Make sure tomcat has permission to modify the folder.
  • Now, re zip the folder and rename the zip file to myportal.war, drop it into tomcat's webapps deploy directory and (hopefully) a working liferay portal will appear.

Deploying a ZK portlet

Here, this guide assumes that users are familiar with and have created a ZK war.

  • First, in order to tell liferay about the portlet, create a class that looks like this:
/**
 * Copyright (c) 2000-2006 Liferay, LLC. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package za.co.mypackage.portlet;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author  Brian Wing Shun Chan
 * @modified Glenn Keith
 */
public class JSPPortlet extends GenericPortlet {

	public void init() throws PortletException {
		editJSP = getInitParameter("edit-jsp");
		helpJSP = getInitParameter("help-jsp");
		viewJSP = getInitParameter("view-jsp");
	}

	public void doDispatch(RenderRequest req, RenderResponse res)
		throws IOException, PortletException {

		String jspPage = req.getParameter("jspPage");

		if (jspPage != null) {
			include(jspPage, req, res);
		}
		else {
			super.doDispatch(req, res);
		}
	}

	public void doEdit(RenderRequest req, RenderResponse res)
		throws IOException, PortletException {

		if (req.getPreferences() == null) {
			super.doEdit(req, res);
		}
		else {
			include(editJSP, req, res);
		}
	}

	public void doHelp(RenderRequest req, RenderResponse res)
		throws IOException, PortletException {

		include(helpJSP, req, res);
	}

	public void doView(RenderRequest req, RenderResponse res)
		throws IOException, PortletException {

		include(viewJSP, req, res);
	}

	protected void include(String path, RenderRequest req, RenderResponse res)
		throws IOException, PortletException {

		PortletRequestDispatcher prd =
			getPortletContext().getRequestDispatcher(path);

		if (prd == null) {
			_log.error(path + " is not a valid include");
		}
		else {
			prd.include(req, res);
		}
	}

	protected String editJSP;
	protected String helpJSP;
	protected String viewJSP;

	private static Log _log = LogFactory.getLog(JSPPortlet.class);

}
  • Next, create a 'liferay-display.xml' file that looks like the following in WEB-INF:
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 4.0.0//EN" "http://www.liferay.com/dtd/liferay-display_4_0_0.dtd">

<display>
	<category name="category.test">
		<portlet id="portletone" />
	</category>
</display>
  • Now, also in the WEB-INF, create a file called 'liferay-portlet.xml' that looks like the following:
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 4.1.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_4_1_0.dtd">

<liferay-portlet-app>
	<portlet>
		<portlet-name>portletone</portlet-name>
		<instanceable>true</instanceable>
	</portlet>
	<role-mapper>
		<role-name>administrator</role-name>
		<role-link>Administrator</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>guest</role-name>
		<role-link>Guest</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>power-user</role-name>
		<role-link>Power User</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>user</role-name>
		<role-link>User</role-link>
	</role-mapper>
</liferay-portlet-app>
  • Liferay 5.2.* : Liferay 5.2 adds cache filters to users' web.xml when deployed on the liferay server. These, however, blocks the zk javascript (*.js) communication. To avoid this, add the property "speed-filters-enabled=false" in the liferay-plugin-package.properties file in the WEB-INF directory.


  • Now again in WEB-INF create a 'portlet.xml' file that looks as follows:
<?xml version="1.0"?>

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
	<portlet>
		<portlet-name>portletone</portlet-name>
		<display-name>Sample JSP Portlet</display-name>
		<portlet-class>za.co.mypackage.JSPPortlet</portlet-class>
		<init-param>
			<name>view-jsp</name>
			<value>/view.zul</value>
		</init-param>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
		</supports>
		<portlet-info>
			<title>Sample JSP Portlet</title>
			<short-title>Sample JSP Portlet</short-title>
			<keywords>Sample JSP Portlet</keywords>
		</portlet-info>
		<security-role-ref>
			<role-name>guest</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
	</portlet>
</portlet-app>
  • Note that the /view.zul reference in this file is the 'index' file of the portlet, and all these files have been referenced as 'portletone', please change this as the name of the war file.
  • Finally, at the top of the web.xml file after <web-app> add the following (followed by the typical ZK stuff):
.
.
.
	<display-name>sample-jsp-portlet</display-name>
	<context-param>
		<param-name>company_id</param-name>
		<param-value>liferay.com</param-value>
	</context-param>
	<listener>
		<listener-class>com.liferay.portal.kernel.servlet.PortletContextListener</listener-class>
	</listener>
.
.
.

Notice that company_id is left as liferay.com.This is because changing the value would also mean digging around the liferay database and it would be hard to find all the places to modify the values.

  • Deploy the resulting war into /home/liferay/deploy directory,
  • Access and sign in to the user's portal, click on 'Add Content' link, under the category 'Test' add 'Sample JSP Portlet'.


Running ZK 5 with Liferay 5.2

Version: Liferay: 5.2.1 and ZK 5


Steps
1.Download Liferay-Tomcat bundle (this example uses liferay-portal-tomcat-6.0-5.2.1)
2.Create a ZK 5 Project

3. Inside the WEB-INF folder, in order to run the ZK application, set up the following four xml files in Liferay.

In order to integrate Liferay with ZK, add the following settings to the portlet.xml setting:

  • <portlet-class>org.zkoss.zk.ui.http.DHtmlLayoutPortlet</portlet-class>
  • And create a zk_page called hello.zul
  • .hello.zul
<?xml version="1.0" encoding="UTF-8"?>
<?page title="Hello"?>
<zk>
<window title="My First window" border="normal" width="200px">
	Hello, World!
	<button label="Hi" onClick='alert("Welcome")'/>
</window>
</zk>
  • portlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app version="1.0" xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
   <description xml:lang="EN">HelloZK</description>
   <portlet-name>HelloZK</portlet-name>
   <display-name xml:lang="EN">HelloZK</display-name>
   <portlet-class>org.zkoss.zk.ui.http.DHtmlLayoutPortlet</portlet-class>
   <expiration-cache>0</expiration-cache>
   <supports>
      <mime-type>text/html</mime-type>
      <portlet-mode>view</portlet-mode>
   </supports>
   <supported-locale>en</supported-locale>
   <portlet-info>
      <title>HelloZK Portlet</title>
      <short-title>HelloZK</short-title>
      <keywords>zk</keywords>
      </portlet-info>
   <portlet-preferences>
   <preference>
      <name>zk_page</name>
      <value>/hello.zul</value>
   </preference>
   </portlet-preferences>
   <security-role-ref>
      <role-name>power-user</role-name>
      </security-role-ref>
      <security-role-ref>
      <role-name>user</role-name>
      </security-role-ref>
   <security-role-ref>
      <role-name>administrator</role-name>
   </security-role-ref>
</portlet>
</portlet-app>
  • liferay-display.xml
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD DISPLAY 2.0.0//EN" "http://www.liferay.com/dtd/liferay-display_2_0_0.dtd">
<display>
<category name="category.sample">
	<portlet id="HelloZK" />
</category>
</display>
  • liferay-portlet.xml
<?xml version="1.0"?>
<!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 5.2.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_5_2_0.dtd">
<liferay-portlet-app>
   <portlet>
     <portlet-name>HelloZK</portlet-name>
     <header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>
   </portlet>
   <role-mapper>
      <role-name>user</role-name>
      <role-link>User</role-link>
   </role-mapper>
   <role-mapper>
      <role-name>power-user</role-name>
      <role-link>Power User</role-link>
   </role-mapper>
   <role-mapper>
      <role-name>administrator</role-name>
      <role-link>Administrator</role-link>
   </role-mapper>
   </liferay-portlet-app>
  • liferay-plugin-package.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plugin-package PUBLIC "-//Liferay//DTD Plugin Package 4.3.6//EN" "http://www.liferay.com/dtd/liferay-plugin-package_4_3_0.dtd">
<plugin-package>
 <name>Hello ZK</name>
 <module-id>/com/demo/test/hellozk/war</module-id>
 <types>
  <type>portlet</type>
 </types>
 <tags>
	<tag>Hello ZK</tag>
 </tags>
 <short-description>
  Hello ZK
 </short-description>
 <change-log>
  Initial Deployment
 </change-log>

 <author>Sam</author>
 <licenses>
  <license osi-approved="true">GPL</license>
 </licenses>
 <liferay-versions>
  <liferay-version>5.1.1+</liferay-version>
  <liferay-version>5.2.1+</liferay-version>
 </liferay-versions>
</plugin-package>


4.Add library-property setting to zk.xml for Liferay

Reason: under IE, using Liferay with ZK will cause HTML Parsing Error (KB927917)
Solution: use jQueryPatch and set appropriate time delay value for browser.

  • zk.xml
<zk>
.
.
.
	<library-property>
		<name>org.zkoss.zk.portlet.PageRenderPatch.class</name>
		<value>org.zkoss.zkplus.liferay.JQueryRenderPatch</value>
	</library-property>
	<library-property>
		<name>org.zkoss.zkplus.liferary.jQueryPatch</name>
		<value>500</value>
	</library-property>
.
.
.
</zk>


5. Export war file
Export a war file called DEPLOY_TO__HelloZK.war, and put this war file under the deploy folder

Liferay deploys war files by its name, when the name DEPLOY_TO__HelloZK.war is used, liferay will deploy this war file to folder HelloZK


Download
DEPLOY_TO__HelloZK.war

Running ZK 5 with Liferay 6

Version: Liferay: 6.0+ and ZK 5

Steps

1. Download Liferay version bundled with Tomcat from Liferay

2. Create a ZK 5 Project

3. Inside the WEB-INF folder, in order to run ZK, users need to add four xml files to set up Liferay. JQueryRenderCachedPatch needs to be added to the zk.xml setting


The main difference between Liferay 5.2 and Liferay 6.0 is liferay-portlet.xml and zk.xml

  • web.xml:
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>HelloZK2</display-name>
	<listener>
		<description>Used to cleanup when a session is destroyed</description>
		<display-name>ZK Session cleaner</display-name>
		<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
	</listener>
	<servlet>
		<description>The ZK loader for ZUML pages</description>
		<servlet-name>zkLoader</servlet-name>
		<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
		<init-param>
			<param-name>update-uri</param-name>
			<param-value>/zkau</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet>
		<description>The asynchronous update engine for ZK</description>
		<servlet-name>auEngine</servlet-name>
		<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>zkLoader</servlet-name>
		<url-pattern>*.zul</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>zkLoader</servlet-name>
		<url-pattern>*.zhtml</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>auEngine</servlet-name>
		<url-pattern>/zkau/*</url-pattern>
	</servlet-mapping>
	<session-config>
		<session-timeout>60</session-timeout>
	</session-config>
	<welcome-file-list>
		<welcome-file>index.zul</welcome-file>
		<welcome-file>index.zhtml</welcome-file>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
	</welcome-file-list>
</web-app>
  • zk.xml:
  • use JQueryRenderCachedPatch
<?xml version="1.0" encoding="UTF-8"?>
<zk>
	<library-property>
		<name>org.zkoss.zk.portlet.PageRenderPatch.class</name>
		<value>org.zkoss.zkplus.liferay.JQueryRenderCachedPatch</value>
	</library-property>
	<library-property>
		<name>org.zkoss.zkplus.liferary.jQueryPatch</name>
		<value>1500</value>
	</library-property>
</zk>
[since 5.0.11]
  • use NonRootContextJQueryRenderPatch instead of JQueryRenderCachedPatch if the home page of Liferay is not under the root(/) path
<?xml version="1.0" encoding="UTF-8"?>
<zk>
	<library-property>
		<name>org.zkoss.zk.portlet.PageRenderPatch.class</name>
		<value>org.zkoss.zkplus.liferay.NonRootContextJQueryRenderPatch</value>
	</library-property>
	<library-property>
		<name>org.zkoss.zkplus.liferary.jQueryPatch</name>
		<value>1500</value>
	</library-property>
</zk>
  • liferay-portlet.xml:

add this to the setting <header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>

 [Since 7.0.3]
  • You don't need <header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript> setting any more.
<liferay-portlet-app>
	<portlet>
		<portlet-name>HelloZK2</portlet-name>
		<!-- don't need this since ZK 7.0.3 -->
		<header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>
	</portlet>
	<role-mapper>
		<role-name>user</role-name>
		<role-link>User</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>power-user</role-name>
		<role-link>Power User</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>administrator</role-name>
		<role-link>Administrator</role-link>
	</role-mapper>
</liferay-portlet-app>
  • liferay-display.xml
<?xml version="1.0"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD DISPLAY 2.0.0//EN" "http://www.liferay.com/dtd/liferay-display_2_0_0.dtd">

<display>
<category name="category.sample">
	<portlet id="HelloZK2" />
</category>
</display>
  • liferay-plugin-package.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plugin-package PUBLIC "-//Liferay//DTD Plugin Package 4.3.6//EN" "http://www.liferay.com/dtd/liferay-plugin-package_4_3_0.dtd">
<plugin-package>
	<name>Hello ZK2</name>
	<module-id>/com/demo/test/hellozk2/war</module-id>
	<types>
		<type>portlet</type>
	</types>
	<tags>
		<tag>Hello ZK2</tag>
	</tags>
	<short-description>
		Hello ZK2
 </short-description>
	<change-log>
		Initial Deployment
 </change-log>

	<author>Sam</author>
	<licenses>
		<license osi-approved="true">GPL</license>
	</licenses>
	<liferay-versions>
		<liferay-version>6.0.0+</liferay-version>
		<liferay-version>6.0.0+</liferay-version>
	</liferay-versions>
</plugin-package>
  • portlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<portlet-app version="1.0"
	xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
	<portlet>
		<description xml:lang="EN">HelloZK2</description>
		<portlet-name>HelloZK2</portlet-name>
		<display-name xml:lang="EN">HelloZK2</display-name>
		<portlet-class>org.zkoss.zk.ui.http.DHtmlLayoutPortlet</portlet-class>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>view</portlet-mode>
		</supports>
		<supported-locale>en</supported-locale>
		<portlet-info>
			<title>HelloZK2 Portlet</title>
			<short-title>HelloZK2</short-title>
			<keywords>zk2</keywords>
		</portlet-info>
		<portlet-preferences>
			<preference>
				<name>zk_page</name>
				<value>/hello.zul</value>
			</preference>
		</portlet-preferences>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
	</portlet>
</portlet-app>

Please download the following war file to view this example in detail

Download DEPLOY_TO__HelloZK2.war

See also

http://devenphillips.blogspot.com/2009/04/developing-liferay-portlets-with-zk.html

ZK 5 / Liferay Integration - jquery conflict

Version History

Version Date Content
     



Last Update : 2015/03/18

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.