Вы находитесь на странице: 1из 96

ZK Installation Guide

For ZK 6

Contents

Articles

ZK Installation Guide

1

Before You Start

1

New to Java

1

New to Java Servlet

2

Quick Start

3

Create and Run Your First ZK Application with Eclipse and ZK Studio

3

Create and Run Your First ZK Application with NetBeans and REM

9

Create and Run Your First ZK Application Manually

13

ZK Background

15

Sample of web.xml for Servlet 3.0

15

Sample of web.xml for Servlet 2.4

16

Sample of web.xml for Servlet 2.3

18

The Content of ZK Binary Distribution

19

Setting up Servers

22

Tomcat

22

JBoss

23

WebSphere

24

Oracle Server

28

WebLogic

29

WebLogic Portal

30

WebLogic Cluster

35

Google App Engine

36

Liferay

40

Pluto

54

Jetty

57

Resin

57

Setting up OS

58

Linux

58

IOS

59

Setting up IDE

60

Eclipse with ZK Studio

60

Eclipse without ZK Studio

61

Maven

63

Setting up Maven on IDE

64

Use ZK Maven Archetype

66

Create and Run ZK Application with Maven Archetype

68

Create and Run ZK Application with Maven

75

Use ZK Maven Repository without IDE

81

XML Editor

90

References

Article Sources and Contributors

91

Image Sources, Licenses and Contributors

92

ZK Installation Guide

ZK Installation Guide

1

Documentation:Books/ZK_Installation_Guide

Before You Start

<comment>http:/

/

wiki/

Before developing a Web application in Java, you have to install Java Development Kit (JDK) and a Servlet container. Here we will guide you through the installation of JDK and the content of ZK binary distribution.

New to Java

You don't need to know Java to use ZK, since all rich user interfaces can be implemented in a HTML-like markup language called ZUML. However, to complete a Web application, you or your teammates need to write some Java code to glue UI and services together. It requires some Java knowledge.

If you haven't installed the following applications on your computer, please download and install them first.

• Java SE Development Kit (JDK)

JDK is a software development for writing application in Java.

Note : we suggest you install this first even some web server already contains one

• Web Server

A Web servlet is used to host the Web application you developed

• ZK Framework

ZK is an Ajax framework simplifying the development of Web applications

Java Tutorials

Here are some good Java tutorials.

Java

URLs

Language Basic

[1] [1]

Class and Object

[2] [2]

[3] [3]

[4] [4]

New to Java

2

Install Java SE Development Kit

ZK supports JDK [5] 1.4, 5, and 6. You could visit the Java website to download and install the version you want.

JDK 6

JDK 5

Installation Instructions: http://java.sun.com/j2se/1.5.0/install.html

Version History

Version

Date

Content

New to Java Servlet

You don't need to know Java Servlet to use ZK, since ZK encapsulates the HTTP requests to higher-level concepts, such as ZUL pages and executions. However, it is helpful if you have some Java Servlet concepts [1] .

Java Servlet Tuturials

A Web container [2] is a server to serve HTTP requests. A software developer who wants to add dynamical content

usually implements a so-called Java Servlet [3] .

A Java Servlet [3] is a Java class responsible for processing HTTP requests and then generating the corresponding

HTTP response (usually in the format of HTML), based on the requirement of your applications.

A Web container is also known as a Servlet container. Tomcat [4] is one of the most famous Web containers.

Rich Java [1] offers a good tutorial about Java Servlet.

New to Java Servlet

3

Version History

Version

Date

Content

References

Quick Start

This chapter describes how to quickly start your first ZK application.

Create and Run Your First ZK Application with Eclipse and ZK Studio

ZK Studio [1] is an Eclipse plugin to simplify the development of ZK applications with Eclipse.

If you prefer to install it manually or use with other IDE, please refer to Create and Run Your First ZK Application Manually.

Prepare Eclipse

Install Eclipse

1. Visit Eclipse download page [2] and download Eclipse IDE for Java EE Developers [3]

2. Uncompress it to a proper directory

3. Then, eclipse is ready to start for use.

For example, you could double-click eclipse.exe to start Eclipse under Windows.

Prerequisites

You can follow ZK Studio Installation Guide [4] to install ZK Studio. There are prerequisites you have to set up before installing ZK Studio:

Java SE Development Kit (JDK)

Java SE Development Kit version 5 or 6 is required in order to run Eclipse, you can download either of them from the links below:

• JDK 6

• JDK 5

Create and Run Your First ZK Application with Eclipse and ZK Studio

4

Eclipse IDE for Java EE Developers

ZK Studio is an Eclipse Plug-in so you must install Eclipse in advance. The following Eclipse IDE for Java EE Developers packages are recommended:

• Eclipse v3.6 (Helios)

• Eclipse v3.5 (Galileo)

Please also see WTP Tutorials Building and Running a Web Application [11] for details.

Application Servers

Before developing web applications in Java with the ZK Ajax Framework, you need to install an application server. Apache Tomcat is one of the most popular Web containers. Tomcat versions 6 and 7 are compatible with ZK Studio and can be downloaded from the link http://tomcat.apache.org/ [4] . Download the zip file of Tomcat distribution and extract it into a proper location (with no illegal characters or space in the pathname). Tomcat requires configuration before it works with Eclipse, please see ZK Studio Essentials for details.

Installing ZK Studio

Please follow the installation guide for your Eclipse version:

• Eclipse v3.6 (Helios)

• Eclipse 3.5 (Galileo)

• Eclipse 3.4 (Ganymede)

• Eclipse 3.3 (Europa)

Defining a Server Runtime

Before deploying and testing your application, you have to install a Web server (such as Tomcat) and specify the server in eclipse. For more information on how to install a server, please also see ZK Installation Guide/Setting up Servers/Tomcat.

To specify the server in eclipse, please do as follows.

1. From menu goto Windows > Preferences

2. Select Server > Runtime Environments, then click Add

3. Select Apache > Apache Tomcat v6.0 and then click Next

4. Browse to and select the root directory of the Web server installed in your computer

• For example, the root directory of Apache Tomcat might be C:\Program Files\Apache Software Foundation\Tomcat 6.0

• For how to install Tomcat, please refer to this section

Create and Run Your First ZK Application with Eclipse and ZK Studio

5

5. Click Finish

Create a "Hello World" application from scratch with ZK Sutdio

Create a new "ZK Project"

With the release of ZK Studio you no longer have to create a new Dynamic Web Project and configure the settings for ZK! You can create a new ZK Project, choose your ZK Package and sit back while ZK Studio does the rest for you.

The following swf demonstrates how to create a new ZK project using Eclipse 3.4 and ZK Studio: <gflash width="945" height="685">Zk_studio_094_new_zk_project.swf</gflash>

For detailed steps, please refer to Create a New ZK Project

Create a new ZUL file

1. Right click on the WebContent folder in the Project Explorer view or the Package Explorer view and

select New > ZUL.

or the Package Explorer view and select New > ZUL . 2. Type test.zul in the

2. Type test.zul in the File name textbox and click Finish.

Create and Run Your First ZK Application with Eclipse and ZK Studio

6

Run Your First ZK Application with Eclipse and ZK Studio 6 3. The newly created ZUL

3. The newly created ZUL File will be opened in the ZUL Editor.

Your First ZK Application with Eclipse and ZK Studio 6 3. The newly created ZUL File

Create and Run Your First ZK Application with Eclipse and ZK Studio

7

Run the application

1. Right click on the MyApp project in explorer and in the Menu dialog select Run As > Run on Server

and in the Menu dialog select Run As > Run on Server 2. Select Apache >

2. Select Apache > Tomcat v6.0 Server in the server type dialog and then click Finish

Apache > Tomcat v6.0 Server in the server type dialog and then click Finish 3. View

Create and Run Your First ZK Application with NetBeans and REM

9

Create and Run Your First ZK Application with NetBeans and REM

REM [1] is a NetBeans module for ZK application development contributed by Mr. Sotohiro Terashima.

Install NetBeans REM

Install NetBeans

1. Download the latest NetBeans IDE from here [2]

2. Follow the installation wizard

Install REM plugin

1. Download the latest REM plugin from here [3]

2. Start NetBeans

3. On NetBeans' main menu bar, select Tools > Plugins.

4. Click on the "Downloaded" tab, followed by "Add Plugins" to open the file explore

followed by "Add Plugins" to open the file explore 5. Navigate to where REM is downloaded

5. Navigate to where REM is downloaded and select the REM plugin

Create and Run Your First ZK Application with NetBeans and REM

10

6. Click "Install" and follow the NetBeans plugin manager prompts

and follow the NetBeans plugin manager prompts Create a New ZK Project 1. On NetBeans main

Create a New ZK Project

1. On NetBeans main menu bar, select "New Project"

2. On the New Project wizard under "Categories", select "Java Web"

menu bar, select "New Project" 2. On the New Project wizard under "Categories", select "Java Web"

Create and Run Your First ZK Application with NetBeans and REM

11

3. Confirm and create a new ZK project.

and REM 1 1 3. Confirm and create a new ZK project. 4. Select the ZK

4. Select the ZK project folder, and right click "Run" to deploy the project on Glassfish

create a new ZK project. 4. Select the ZK project folder, and right click "Run" to

Create and Run Your First ZK Application with NetBeans and REM

12

Deploy the ZK Demo Project

1. On NetBeans main menu bar, select "New Project"

2. On the New Project wizard under "Categories", expand the "Samples" folder and select "Java Web"

the "Samples" folder and select "Java Web" 3. Select "ZK505 Demo Project" under

3. Select "ZK505 Demo Project" under "Projects"

4. Select the ZK demo project and right click to select "Run" to deploy the ZK demo

under "Projects" 4. Select the ZK demo project and right click to select "Run" to deploy

Create and Run Your First ZK Application with NetBeans and REM

13

Version History

Version

Date

Content

References

Create and Run Your First ZK Application Manually

Prepare the server

Install Tomcat

First, you have to prepare a Web server. You can use any Web servers that support Java Servlet (2.3 or later). Here we introduce the installation of Tomcat [1] . For other servers and more information, please refer to Setting up Servers.

1. Visit Tomcat Official Site [4]

2. Select the correct binary distribution for your environment and download

• For Windows, you might download and execute 32-bit/64-bit Windows Service Installer [2] , and then follow the instructions

• For any download/installation problems, please refer to http://tomcat.apache.org/tomcat-6.0-doc/index. html

Download ZK Libraries

ZK libraries (Now is zk-bin-5.0.4.zip) can be downloaded from ZK Download [3] and then save it to a proper location.

Create your first application

Here shows you how to create a web application manually without IDE or other tools.

Create Web application

ZK Web Applications use a standard directory structure defined in the Servlet specification.

When developing ZK web applications, you must follow this structure so that the application can be deployed in any J2EE compliant web servers.

All you need to do is create a web application directory with related files.

• Now i create one for example named myZK

All you need to do is create a web application directory with related files. • Now

Create and Run Your First ZK Application Manually

14

Install Library Distribution

1. Unzip zk-bin-5.0.4.zip

2. Copy JAR files under following list to myZK/WEB-INF/lib

• {YOUR_ZK_UNZIP_FOLDER}/dist/lib

• {YOUR_ZK_UNZIP_FOLDER}/dist/lib/ext

• {YOUR_ZK_UNZIP_FOLDER}/dist/lib/zkforge

Create Deployment Descriptor(Web.xml)

web.xml is called the web application deployment descriptor. This is an XML file that defines servlets, servlet mappings, listeners, filters, welcome files etc.

The deployment descriptor is a heart of any J2EE web applications, so every web application must have a web.xml deployment descriptor directly under WEB-INF folder.

• For the content of web.xml, please refer to Sample of web.xml for Servlet 3.0, Sample of web.xml for Servlet 2.4 or Sample of web.xml for Servlet 2.3, depending on your Web server support.

Create First ZUL file

Here is a simple zul file named hello.zul.

<window title="My First ZK Application" border="normal"> Hello World! </window>

Pack your project

1. Compress the myZK directory(e.g. myZK.zip)

2. Rename myZK.zip to myZK.war

3. Done!!

Confirm your ZK Web Archive (WAR) file

myZK.war

¦ hello.zul

¦

- WEB-INF

¦

¦

- lib

web.xml

*.jar

Create and Run Your First ZK Application Manually

15

Version History

Version

Date

Content

References

ZK Background

This chapter describes the information of ZK installation, such as the sample of web.xml and the content of the binary distribution.

Sample of web.xml for Servlet 3.0

ZK 6 supports Servlet 3.0 Pluggability, so you don't have to configure WEB-INF/web.xml at all.

<web-app xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

version="3.0">

<description><![CDATA[My ZK Application]]></description> <display-name>MyApp</display-name> </web-app>

On the other hand, if metadata-complete=truewas specified in WEB-INF/web.xml (i.e., the support of pluggability is disabled), you have to configure ZK servlets and listeners manually as described in the Sample of web.xml for Servlet 2.4.

Version History

Version

Date

Content

6.0.0

December 2011

The support of Servlet 3.0 Pluggability was introduced.

Sample of web.xml for Servlet 2.4

16

Sample of web.xml for Servlet 2.4

After the ZK libraries have been deployed to a Web application, we have to configure web.xml to install the required Servlets, listener and mapping: DHtmlLayoutServlet [1] , DHtmlUpdateServlet [2] , and HttpSessionListener [3] .

Here is the sample web.xml for servers that support Servlet 2.4 and later.

Notice that if you are using Servlet 3, you generally don't need to set up web.xml unless you'd like to configure it different.

Notice that the ZK demo distribution has several web.xml files under the MyApp/WebContent/WEB-INF directory: web.servlet-3.xml (for servers supporting only Servlet 3), web.servlet-2.4.xml (for servers supporting Servlet 2.4 or later), and web.servlet-2.3.xml (for servers supporting only Servlet 2.3). You could copy one of them instead of creating from scratch.

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.4" 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">

<description><![CDATA[My ZK Application]]></description> <display-name>MyApp</display-name>

<listener> <description>ZK listener for session cleanup</description> <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class> </listener> <servlet> <description>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-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> <!-- Optional. Uncomment it if you want to use richlets. <servlet-mapping>

Sample of web.xml for Servlet 2.4

17

<servlet-name>zkLoader</servlet-name> <url-pattern>/zk/*</url-pattern> </servlet-mapping> --> <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>auEngine</servlet-name> <url-pattern>/zkau/*</url-pattern> </servlet-mapping>

<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>

Version History

Version

Date

Content

References

Sample of web.xml for Servlet 2.3

18

Sample of web.xml for Servlet 2.3

Here is the sample web.xml for servers that support Servlet 2.3 only. Though not necessary, many old servers still requires JDK 1.4.

Notice that the ZK demo distribution has two web.xml files under the MyApp/WebContent/WEB-INF directory: web.xml (for servers supporting Servlet 2.4 or later), and web.servlet-2.3.xml (for servers supporting only Servlet 2.3). You could copy one of them instead of creating from scratch.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app> <description><![CDATA[My ZK Application]]></description> <display-name>MyApp</display-name>

<listener>

<listener-class>org.zkoss.zk.ui.http.HttpSessionListener23</listener-class>

</listener> <servlet> <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>

<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>

<!-- Optional. Uncomment it if you want to use richlets. <servlet-mapping> <servlet-name>zkLoader</servlet-name>

Sample of web.xml for Servlet 2.3

19

<url-pattern>/zk/*</url-pattern>

</servlet-mapping>

-->

<servlet-mapping>

<servlet-name>auEngine</servlet-name>

<url-pattern>/zkau/*</url-pattern>

</servlet-mapping>

<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>

Version History

Version

Date

Content

The Content of ZK Binary Distribution

Directory Structure

The content of the ZK binary distribution is as follows.

/doc

This directory holds the documents including release notes and license.

/dist

/dist/lib

This directory holds the ZK libraries

The Content of ZK Binary Distribution

20

Filename

Description

License

Shipped

zcommon.jar

ZK's common library (org.zkoss.*)

LGPL

All

zweb.jar

ZK's Web library (org.zkoss.web.*

LGPL

All

zk.jar

ZK's core (org.zkoss.zk.*)

LGPL

All

zul.jar

ZUL components (org.zkoss.zul.*)

LGPL

All

zhtml.jar

ZK HTML (ZHTML) components (org.zkoss.zhtml.*)

LGPL

All

zkbind.jar

ZK Bind, including data binding and MVVM.

LGPL

All

zkplus.jar

ZK utilities (org.zkoss.zkplus.*)

LGPL

All

zel.jar

ZK's implementation of EL 2.2. It is based on Apache Tomcat 7's EL 2.2 implementation.

Apache

All

zkex.jar

ZK professional ZUL components and utilities (org.zkoss.zkex.*)

Commercial

ZK PE and EE only

zml.jar

ZK XML components (org.zkoss.zml.*)

Commercial

ZK PE and EE only

zkmax.jar

ZK enterprise components and utilities (org.zkoss.*)

Commercial

ZK EE only

/dist/lib/zkforge

This directory holds the additional components and libraries. It is optional depending on whether you need them.

There are three kinds of binary distributions: CE, PE and EE. If not stated explicitly, it is shipped in all distributions.

Filename

Description

License

Version

Shipped

sapphire.jar

Required if you want to use the sapphire theme.

LGPL

6.0.0

All

silvertail.jar

Required if you want to use the silvertail theme.

LGPL

6.0.0

All

ckez.jar

Required if you want to use ZK CKeditor component.

LGPL

3.6.0.1

All

timelinez.jar

Required if you want to use ZK Timeline component.

GPL

2.3.1_50

ZK PE and EE only

timeplotz.jar

Required if you want to use ZK Timeplot component.

GPL

1.1_50

ZK EE only

gmapsz.jar

Required if you want to use ZK Google Maps component.

GPL

2.0.52

ZK EE only

zuljsp.jar

Required if you want to use ZK JSP Tags.

GPL

2.0

ZK EE only

/dist/lib/ext

This directory holds the external libraries required to run ZK. Since these libraries are common, you might have already installed them in your Servlet container. These jar files are optional. You can choose whether to copy depending on your requirements.

The Content of ZK Binary Distribution

21

Filename

Description

License

Version

Shipped

• commons-fileupload.jar

Required if you want

Apache

• Commons Fileupload 1.2.1

All

• commons-io.jar

to upload files with them.

• Commons IO 1.3.1

• jcommon.jar

Required if you want

LGPL

• JFreeChart 1.0.13

ZK PE and EE only

• jfreechar.jar

to use ZUL's chart component.

• JCommon 1.0.16

• jasperreports.jar

Required if you want

LGPL

• Jasper Reports 3.7.0(itext: 2.1.7, commons-collections:

ZK PE and EE only

• itext.jarjxl.jar

to use the jasperreport

(jasperreports)

3.2.1, commons-logging: 1.1.1, commons-digester: 2.0, jxl: 2.6.12, poi: 3.2)

• poi.jar

component.

 

• commons-collections.jar

• Note: poi.jar is required if you want to use Apache POI to generate Microsoft Excel format. And, jxl.jar is required only if you want to use JExcelApi to generate the Microsoft Excel format.

• commons-logging.jar

• commons-digester.jar

• bsh.jar

Required if you want scripting in Java interpreter (BeanShell).

LGPL

BeanShell 2.0b4

All

• Filters.jar

Required if you want to use the captcha component.

Apache

JH Labs Java Image Filters

ZK PE and EE only

• The interpreters for Groovy (groovy.jar), Ruby (jruby.jar), Python (jython.jar), JavaScript (js.jar), MVEL (mvel.jar) and OGNL (ognl.jar) are not shipped with the binary distribution since ZK 6. You could get them from their websites, or from ZK's Git repository (https://github.com/zkoss/zk/tree/master/dist/lib/ext).

/dist/src

This directory holds the source codes in JAR format. These JAR files are used for debugging in IDE, such as Eclipse and NetBeans. You cannot build the binary libraries from these. Rather, download and uncompress

zk-src-6.0.0.tar.gz.

/dist/xsd

This directory holds the XSD files that might be useful to develop ZK applications.

/dist/WEB-INF

This directory holds the sample configuration file (web.xml and portlet.xml) and the TLD files. These TLD files are part of JAR files so they are loaded automatically. We put them here mainly for your reference only.

Version History

Version

Date

Content

Setting up Servers

Setting up Servers

22

If you are new to Web servers, you could start with ZK Installation Guide/Setting up Servers/Tomcat.

Tomcat

Install Tomcat

1. Visit Tomcat Official Site [4]

2. Select the correct binary distribution for your environment and download

• For Windows, you might download and execute 32-bit/64-bit Windows Service Installer [2] , and then follow the instructions

• Any download/install problem, please refer to http://tomcat.apache.org/tomcat-6.0-doc/index.html

Deploy

Deploy ZK demo application(optional)

The simplest way to test drive ZK existed application is to download and install the ZK demo application.

This step is optional. You could skip it if you prefer to start creating your own application directly.

1. Download the lastest zkdemo at http://sourceforge.net/projects/zk1/files/ZK/(e.g. zk-demo-5.0.4.zip)

2. Unzip zk-demo-5.0.4.zip

3. Copy zkdemo.war under the zk-demo-5.0.4 directory to $TOMCAT_HOME/webapps.

4. Start/ReStart the tomcat services (In some cases, you may need to restart your container if it is running.)

5. Visit http://localhost:8080/zkdemo, and then play around with the demo application

Deploy war file to Tomcat is very easy but there're something you need to know

• Tomcat will unzip the war file to filename\ directory automatically

• You can NOT modify the content of filename\ directory unless you remove the war file, or your modification will not work.

• For more information about Tomcat's deployer, please refer to http://tomcat.apache.org/tomcat-6.0-doc/ deployer-howto.html

Tomcat

23

Deploy your application with IDE

When developing an application, we usually use IDE to deploy it. For more information, please refer to the document of your IDE.

If you are new to Java IDE, you might take a look at Setting up Eclipse with ZK Studio.

Version History

Version

Date

Content

JBoss

JBoss 4.0 and above

1. Download Jboss from http://www.jboss.com/downloads/index and install it,if you haven't installed it.

2. Test the Jboss using link http://localhost:port, if it's OK stop the server.

3. Unzip zk-demo-XXX.zip or zk-demo-XXX.tar.gz

4. Copy dist/lib/*.jar and dist/lib/*/*.jar to the $JBOSS_HOME/server/default/lib

5. Copy zkdemo.war to $JBOSS_HOME/server/default/deploy

6. Start the server.

7. Browse to http://localhost/zkdemo/userguide or http://localhost:8080/zkdemo/userguide depending on you configuration for JBoss.

by Juan Jose Buendia Mardones (Chile)

JBoss 3.2.2 + tomcat 4.1

1. Follow the instruction to install ZK Ajax on tomcat 4.1.

2. Download the following files and copy them to the lib directory under default.

• bsh-bsf-2.0b4.jar

• bsh-core-2.0b4.jar

• bsh-2.0b2.jar

3. Change the web.xml so that it will fit servlet 2.3 specifications.

4. We are still working on some problems and I will update this record when I'll have the full solution.

When I tried the solution given by Mars Chen some of the components built upon the Jboss platform didn't function anymore. When doing my solution however one of the ZK components (the upload file) didn't work. But for now I did a workaround to use tomcat 5.5 in the background.

by Yaniv Ran (USA)

2.1 There I got another simple solution: using ZK distribution's bsh.jar into JBoss lib directory to replace bsh-core-version.jar.

Please refer BeanShell official site. == http:/ / www. beanshell. org/ download. html == The bsh-version.jar containas all files in bsh-core-version.jar.

by Mars Chen (Taiwan)

JBoss

24

Version History

Version

Date

Content

WebSphere

IBM WebSphere

1. IBM offers a websphere application server community edition. Please go to http://www-128.ibm.com/ developerworks/downloads/ws/wasce/?S_TACT=105AGX10&S_CMP=WASCE to download it.

2. Follow the instruction to download, you might need to register for an account if you don't already have one.

3. Under downloads, choose Server and 32bit IBM SDK 1.4.2 SR4-1, procees to download.

4. Start the installer and accepts all defaults.

5. Once installation is completed, go to All Programs->IBM Websphere->Application Server->Profiles->Default->Start the Server, this will start the server.

7. After deployed, applications can be access via http://localhost:9080/myapp

8. For additional documentation and tutorials, go to http://publib.boulder.ibm.com/wasce/Front_en.html

ZK supports Servlet 2.3, 2.4 and later. The only difference is the content of WEB-INF/web.xml is a little bit different. Please refer to Sample of web.xml and Sample of web.xml for Servlet 2.3.

IBM WebSphere 7

Import war file

1. Applications -> Application Types -> WebSphere enterprise applications -> Click install button

-> Application Types -> WebSphere enterprise applications -> Click install button 2. Select war file to

2.

Select

war

file

to

WebSphere

25

WebSphere 2 5 3. Select Fast P Find web application port 1. Servers -> Server Types

3. Select Fast P

Find web application port 1. Servers -> Server Types -> WebSphere application servers -> Click "server1"

Types -> WebSphere application servers -> Click "server1" 2. Communcations -> Click on "Ports"

2.

Communcations

->

Click

on

WebSphere

26

WebSphere 2 6 3.

3.

WebSphere 2 6 3.

WebSphere

27

View Web application

WebSphere 2 7 View Web application Version History Version Date Content

Version History

Version

Date

Content

Oracle Server

Oracle Server

28

Oracle OC4J and Oracle OPMN Release 3

OC4J 10.1.3 (release 3) is the first production version of Oracle Containers For Java to support J2EE 1.4 specification (Servlet 2.4).

1. Download OC4J 10.1.3 or later from http://www.oracle.com and install it.

2. You must setup OC4J to run with the -userThreads parameter at the command line (oc4j.cmd, on OPMN this is done inside the opmn.xml <data id="oc4j-options" value="-userThreads" />)

3. Unzip zk-1.2.0-2006-04-07.zip or later version

4. Copy dist/lib/*.jar and dist/lib/ext/*.jar to the $OC4J_HOME/j2ee/home/applib

5. Start OC4J server and enter a new oc4jadmin's password if prompted or restart the server if it is already up

6. Open "Enterprise Manager" application - just browse to http://localhost:8888/em/

7. Login as oc4jadmin and go to Applications --> Deploy page

8. Deploy zkdemo.war (follow the on-screen instructions)

• Substitute "/zkdemo" with the context uri you entered in EM during deployment

• Start OC4J Server:

bin/oc4j -start

10.1.2 and earlier

Prior versions 10.1.2.0.2, 10.1.2.0.1 supports only J2EE 1.3 (with Servlet 2.3), WEB-INF/web.xml shall be replaced with Sample of web.xml for Servlet 2.3.

Notice that ZK supports Servlet 2.3 (and even JDK 1.4) but the web.xml configuration file is a bit different.

Version History

Version

Date

Content

WebLogic

WebLogic

29

1. Download Weblogic 9.1 from [1]

2. Start the Weblogic installer and accept all defaults.

3. Once the default installation is complete, create a weblogic domain by clicking Start->Programs->BEA products->Tools->Configuration Wizard.

4. Select "Create New Weblogic Domain" and click Next.

5. Accept the defaults on "Select Domain Source" and click Next.

6. Enter a password in "Configure Administrator Username and Password" and click Next.

7. Accept all defaults on "Configure Server Start Mode and JDK" and click Next.

8. Selct No on Configure Environment Setting and Services" and click Next.

9. Accept all defaults on "Create Weblogic Domain and click Create.

10. Once the domain is created, check the check box labeled "Start Admin Server" and click Done.

11. The server will start up.

12. The HTTP port is default to 7001 unless you change it.

The easiest way to deploy your application is to copy your war/ear (it could be in an exploded format) to the autodeploy directory under the weblogic installaton directory. If you followed the instruction above that directory is located at C:\bea\user_projects\domains\base_domain\autodeploy. When you place your war/ear file in that directory, weblogic will detect it and do a hot deployment.

If you want to copy ZK libraries to the domain, put them under c:/bea/user_projects/domains/base_domain/lib

Libraries that have to be copied include bsh.jar, commons-fileupload.jar, commons-el.jar, pxcommon.jar, pxweb.jar, zk.jar, zul.jar, and zhtml.jar.

Version History

Version

Date

Content

References

WebLogic Portal

WebLogic Portal

30

Introduction

Weblogic Portal provides several types of portlets, if you want to convert an existing zul page into a portlet, you can consider using a JSP portlet.

Add JSP/HTML Portlet

1. Right click on portlet folder > [New] > [Portlet]

Add JSP/HTML Portlet 1. Right click on portlet folder > [New] > [Portlet] 2. Give a

2. Give a file name then click Next.

WebLogic Portal

31

WebLogic Portal 3 1 3. Select JSP/HTML Portlet then click Next . 4. Check Minmizable and

3. Select JSP/HTML Portlet then click Next.

3 1 3. Select JSP/HTML Portlet then click Next . 4. Check Minmizable and Maximizable and

WebLogic Portal

32

WebLogic Portal 3 2 Add Zul page to your webapp • Create myZulPage.zul in the WebContent/portlet/myzulpage

Add Zul page to your webapp

• Create myZulPage.zul in the WebContent/portlet/myzulpage folder.

WebLogic Portal 3 2 Add Zul page to your webapp • Create myZulPage.zul in the WebContent/portlet/myzulpage

WebLogic Portal

33

Add portlet to portal page

1. Drag myZulPage.portlet to "Page 1" in the index.portal.

Portal 3 3 Add portlet to portal page 1. Drag myZulPage.portlet to "Page 1" in the

2. Done.

Portal 3 3 Add portlet to portal page 1. Drag myZulPage.portlet to "Page 1" in the

WebLogic Portal

34

Run the weblogic server

• Run the server and access your application in the following link, http://localhost:7001/myPortalWebProject/ index.portal [1] .

index.portal [ 1 ] . Version History Version Date Content References [1]

Version History

Version

Date

Content

References

WebLogic Cluster

WebLogic Cluster

35

Before You Start

You have to configure the following setting for ZK and Weblogic.

zk.xml

• Turn on Serializable UI Factory for ZK, please refer to this documentation.

<zk>

<system-config> <ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-clas </system-config> <!-- clustering environment, since ZK 5.0.8--> <listener> <listener-class>org.zkoss.zkplus.cluster.ClusterSessionPatch</listener-class> </listener>

</zk>

weblogic.xml

• Add a weblogic.xml under XXX/WEB-INF folder(XXX is like ZKsandbox in the war file)

For example,

<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN"

"http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">

<weblogic-web-app>

<session-descriptor>

<session-param>

<param-name>PersistentStoreType</param-name>

<param-value>replicated</param-value>

</session-param>

</session-descriptor>

</weblogic-web-app>

As mentioned in Weblogic's document [1]

replicated Same as memory, but session data is replicated across the clustered servers.

WebLogic Cluster

36

Setting up Weblogic Clusters

After those things done above, please follow the official document to set up a Weblogic Cluster Server here [2] .

Version History

Version

Date

Content

5.0.8

June 2011

Add ClusterSessionPatch listener to zk.xml for enforce Weblogic to write session.

References

Google App Engine

Get Your App Engine Account Ready

First, you have to sign up an App Engine [1] account and download the App Engine SDK. Refer to the official website [1] for details.

To use Google App Engine for Java, you have to take one additional step: sign up here [2] .

In addition, your application must be ready for clustering, such as serializable. For more information, please refer to ZK Developer's Reference: Clustering/Programming Tips.

Configure Your App Engine Project

Here we assume you created a App Engine project. If not, please refer here [3] .

There are three files that you have to configure: web.xml, zk.xml and appengine-web.xml. They all reside in the WEB-INF directory.

The web.xml File

The content is similar to other ZK application except the AU engine has to be mapped to /zkau, too (in additions to /zkau/*. Otherwise, AU requests won't be sent to the AU engine. Here is is an example.

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"> <listener> <description>ZK listener for session cleanup</description> <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class> </listener>

<servlet>

<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>

Google App Engine

37

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet>

<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>auEngine</servlet-name>

<url-pattern>/zkau/*</url-pattern>

</servlet-mapping>

<servlet-mapping>

<servlet-name>auEngine</servlet-name>

<url-pattern>/zkau</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.zul</welcome-file>

<welcome-file>index.zhtml</welcome-file>

<welcome-file>index.html</welcome-file>

</welcome-file-list>

</web-app>

The zk.xml File

Google App Engine is a cloud service, so you have to enable the clustering: disable event threads and use serializable UI factory. In addition, Google App Engine doesn't allow users to create a working thread, so we have to disable the resend mechanism.

Here is an example.

<zk>

<!-- clustering environment --> <system-config> <disable-event-thread/> <ui-factory-class>org.zkoss.zk.ui.http.SerializableUiFactory</ui-factory-clas </system-config> <!-- clustering environment (available since ZK 5.0.8)--> <listener> <listener-class>org.zkoss.zkplus.cluster.ClusterSessionPatch</listener-class> </listener> <!-- [Required if ZK 5] disable the use of LogManager (prohibited by GAE). --> <library-property> <name>org.zkoss.util.logging.hierarchy.disabled</name> <value>true</value> </library-property>

Google App Engine

38

<!-- GAE doesn't allow user's thread --> <client-config>

<resend-delay>-1</resend-delay>

</client-config>

</zk>

With ZK 6 or later, you don't have to specify the library property called org.zkoss.util.logging.hierarchy.disabled. Rather, just not to configure the logging at all (i.e., do not use any feature specified in ZK Developer's Reference/Supporting Utilities/Logger). Then, java.util.logging.LogManager won't be used (which is prohibited by GAE).

The appengine-web.xml File

App Engine requires one addition configuration file named appengine-web.xml. It resides in the WEB-INF directory.

<sessions-enabled>true</sessions-enabled>

<static-files> <exclude path="/**.zul"/> <exclude path="/**.zhtml"/> </static-files> <resource-files> <include path="/**.zul"/> <include path="/**.zhtml"/> </resource-files>

More Information

Due to the way App Engine serializes sessions, you have to use ZK 3.6.2 or later. In additions, there are some other limitations.

• You cannot define functions in zscript, since BeanShell's method can not be serialized correctly [4] .

• You cannot use captcha due to the limit support of AWT [5]

[4] It runs correctly locally but not if uploaded. It could be done by specifying as a library property to disable the serializing of zscript methods for the whole application.

[5] You will see a warning,

Component captcha ignored., in the application log.

Memory Limitation and Solutions

GAE limits the session memory to 1 mega bytes. If a user visits several pages (with different URLs) in the same browser session, there would be several desktops created and stored in the session, and it might run out the 1 mega bytes. To avoid this, you can implement DesktopInit (http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/ util/ DesktopInit. html#) to remove other desktops in the desktop cache and specify it in WEB-INF/zk.xml as a listener. For example,

Google App Engine

39

public class MyDesktopInit implements DesktopInit {

public void init(Desktop desktop, Object req) throws Exception { HttpServletRequest request = (HttpServletRequest) req; //Remove old Desktop String oldDesktopId = (String) request.getSession().getAttribute("currentDesktopId"); WebAppCtrl ctrl = (WebAppCtrl)Executions.getCurrent().getDesktop().getWebApp(); DesktopCache dc = ctrl.getDesktopCache(desktop.getSession()); dc.removeDesktop(dc.getDesktop(oldDesktopId)); //Add new Desktop request.getSession().setAttribute("currentDesktopId", desktop.getId());

}

}

Sample

In additions, you could visit Bitbucket (https://bitbucket.org/antiso/zktest/src/143186a3ae8b/src/main/). It is a sample project developed by Vladimir Sosnin, and the working demo is here (http:/ / tags42. appspot. com/ borderlayout/borderlayout.zul).

Version History

Version

Date

Content

5.0.8

June 2011

Add ClusterSessionPatch listener to zk.xml for enforce GAE to write session.

5.0.9

September

In 5.0.7/5.0.8, we introduced a feature allowing developers to log the serialization. Unfortunately, it broke one of GAE

2011

restriction: java.util.logging.LogManager is not accessible. It is fixed in 5.0.9 but specifying a library property called org.zkoss.util.logging.hierarchy.disabled in WEB-INF/zk.xml.

Liferay

Liferay

40

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 [1] 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 [1]

• 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/XMLSch

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</f

Liferay

41

</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:

Liferay

42

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.

*/

Liferay

43

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);

}

Liferay

44

 

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/

<display> <category name="category.test"> <portlet id="portletone" />

Liferay

45

</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" "htt

<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>

Liferay

46

<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</lis

</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'.

Liferay

47

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"

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>

Liferay

48

<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/ <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" "htt <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.li <plugin-package>

Liferay

49

<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>

Liferay

50

5. Export war file

Export a war file called DEPLOY_TO

Liferay deploys war files by its name, when the name DEPLOY_TO this war file to folder HelloZK

HelloZK.war,

and put this war file under the deploy folder

HelloZK.war

is used, liferay will deploy

Download

DEPLOY_TO

HelloZK.war

[2]

Running ZK 5 with Liferay 6

Version: Liferay: 6.0.4 and ZK 5

Steps

1. Download Liferay version bundled with Tomcat from Liferay [3]

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

• 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>