Thursday 9 May 2013

JCarousal in Zk+Liferay portlet

Now lets make JCarousal in our zk Liferay portlet...




I have use refrence of this site to make this Carousal.You can download all the necessary js and css from this site.
Lets start step by step...

1)Download necessary files as well as the images of next and previous button from that site you can use firebug also to download those stuff. 

2)Download  jquery.jcarousel.min.js and jQuery.js and put these files in docroot/js folder.

3) Update liferay-portlet.xml as given below:


 <?xml version="1.0"?>  
 <!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.1.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_1_0.dtd">  
   <liferay-portlet-app>   
     <portlet>   
       <portlet-name>zk-hello-world</portlet-name>   
       <icon>/icon.png</icon>   
       <instanceable>false</instanceable>   
       <header-portlet-css>/css/main.css</header-portlet-css>   
       <header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>   
       <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>   
       <footer-portlet-javascript>/js/jquery-1.8.3.min.js</footer-portlet-javascript>   
       <footer-portlet-javascript>/js/jquery.jcarousel.min.js</footer-portlet-javascript>   
       <css-class-wrapper>zk-hello-world-portlet</css-class-wrapper>  
     </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>  

4)Add The content of the skin.css to docroot/css/main.css file.

In that we have to change just each  url of the images like given below:


  just check the format of the url /{portlet-name}/images/{name of the image}

5) You have to download that images named next-horizontal.png and prev-horizontal.png likewise from  the above site and put those images in docroot/images folder.

6) Update the view.zul as given below:


 <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>  
 <zk xmlns:html="http://www.w3.org/1999/xhtml">  
 <window title="jcarousel" id="window" apply="com.liferay.zk.controller.ZkController">  
 <div class=" jcarousel-skin-tango"><div class="jcarousel-container jcarousel-container-horizontal" style="position: relative; display: block;"><div class="jcarousel-clip jcarousel-clip-horizontal" style="position: relative;">  
 <html:ul class="jcarousel-list jcarousel-list-horizontal" id="mycarousel" style="overflow: hidden; position: relative; top: 0px; margin: 0px; padding: 0px; left: 0px; width: 950px;">  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="1"><image width="75" height="75" src="http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-2 jcarousel-item-2-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="2"><image width="75" height="75" src="http://static.flickr.com/75/199481072_b4a0d09597_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-3 jcarousel-item-3-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="3"><image width="75" height="75" src="http://static.flickr.com/57/199481087_33ae73a8de_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-4 jcarousel-item-4-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="4"><image width="75" height="75" src="http://static.flickr.com/77/199481108_4359e6b971_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-5 jcarousel-item-5-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="5"><image width="75" height="75" src="http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-6 jcarousel-item-6-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="6"><image width="75" height="75" src="http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-7 jcarousel-item-7-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="7"><image width="75" height="75" src="http://static.flickr.com/58/199481218_264ce20da0_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-8 jcarousel-item-8-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="8"><image width="75" height="75" src="http://static.flickr.com/69/199481255_fdfe885f87_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-9 jcarousel-item-9-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="9"><image width="75" height="75" src="http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg"></image></html:li>  
   <html:li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-10 jcarousel-item-10-horizontal" style="float: left; list-style: none outside none;" jcarouselindex="10"><image width="75" height="75" src="http://static.flickr.com/70/229228324_08223b70fa_s.jpg"></image></html:li>  
  </html:ul>  
  </div><div class="jcarousel-prev jcarousel-prev-horizontal jcarousel-prev-disabled jcarousel-prev-disabled-horizontal" style="display: block;"></div>  
  <div class="jcarousel-next jcarousel-next-horizontal" style="display: block;"></div></div>  
  </div>  
 </window>  
 </zk>  

7)Update the content of the ZkController.java as given below:

 package com.liferay.zk.controller;  
 import org.zkoss.zk.ui.select.SelectorComposer;  
 import org.zkoss.zk.ui.util.Clients;  
 import org.zkoss.zul.Window;  
 public class ZkController extends SelectorComposer<Window> {  
      private static final long serialVersionUID = 1L;  
 @Override  
 public void doAfterCompose(Window comp) throws Exception {  
      // TODO Auto-generated method stub  
      super.doAfterCompose(comp);  
      //You can change the visible app by java controller you can handle all the carousal function with this below line  
      Clients.evalJavaScript("jQuery('#mycarousel').jcarousel({ scroll: 1,visible: 3});");  
 }  
 }  

8) Project structure:

JCarousal Project structure for zk+liferay portlet
Now you can also create jCarousal dynamically from controller side by adding li element in ul element and apply the jCarousal function to ul element by its id.We will See it in next post....:D
And its done :) deploy it and there you go...GOOD DAY


Wednesday 8 May 2013

WYSIWYG Editor In Liferay-Zk portlet

Hi guys,

In this post, 

We are going to see how ckeditor can be integrated in liferay+zk portlet and also how to get content from it ans show that content on our page.

 We have already made simple portlet in liferay which was integrated with zk framework.You can read that thing in my previous posts.

1) Add new class ZkController.java and add below content and put this file in  com.liferay.zk.controller       package.

 package com.liferay.zk.controller;  
 import org.zkforge.ckez.CKeditor;  
 import org.zkoss.zk.ui.select.SelectorComposer;  
 import org.zkoss.zk.ui.select.annotation.Listen;  
 import org.zkoss.zk.ui.select.annotation.Wire;  
 import org.zkoss.zul.Html;  
 import org.zkoss.zul.Window;  
 public class ZkController extends SelectorComposer<Window> {  
      /**  
       *   
       */  
      private static final long serialVersionUID = 1L;  
      @Wire("#ed")  
      private CKeditor ed;  
      @Wire("#showHtm")  
      private Html showHtm;  
      @Listen("onClick = #showBtn")  
      public void showContent(){  
      //ed.setValue("hello");  
      showHtm.setContent(ed.getValue());  
      }  
 }  

2)Edit view.zul as given below:

 <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>  
 <zk >  
 <window title="hello" id="window" apply="com.liferay.zk.controller.ZkController">  
 <ckeditor id="ed" width="600px"></ckeditor>  
 <button id="showBtn" label="${c:l('button-label')}"></button>  
 <html id="showHtm" style="padding:10px;overflow:auto;max-height:300px"></html>  
 </window>  
 </zk>  

3)Edit zk-label.properties as below in docroot/properties folder

 button-label = show  

4)Add new file ckez-bind-addon.xml under WEB-INF folder and put below content in it:

 <?xml version="1.0" encoding="UTF-8"?>  
 <language-addon>  
   <!-- The name of this addon. It must be unique -->  
   <addon-name>ckezbind</addon-name>  
   <!-- Specifies what other addon this depends  
   <depends></depends>  
   -->  
   <!-- Which language this addon will be added to -->  
   <language-name>xul/html</language-name>  
   <component>  
     <component-name>ckeditor</component-name>  
     <extends>ckeditor</extends>  
     <annotation>  
       <annotation-name>ZKBIND</annotation-name>  
       <property-name>value</property-name>  
       <attribute>  
         <attribute-name>ACCESS</attribute-name>  
         <attribute-value>both</attribute-value>  
       </attribute>  
       <attribute>  
         <attribute-name>SAVE_EVENT</attribute-name>  
         <attribute-value>onChange</attribute-value>  
       </attribute>  
       <attribute>  
         <attribute-name>LOAD_REPLACEMENT</attribute-name>  
         <attribute-value>value</attribute-value>  
       </attribute>  
       <attribute>  
         <attribute-name>LOAD_TYPE</attribute-name>  
         <attribute-value>java.lang.String</attribute-value>  
       </attribute>  
     </annotation>  
   </component>  
 </language-addon>  

5)Enter below one entry in zk.xml in under <zk> tag


 <language-config>  
     <addon-uri>/WEB-INF/ckez-bind-addon.xml</addon-uri>  
   </language-config>  

6) Add ckez.jar in lib folder. You can download it from here.

7)Add portal dependency in liferay-plugin-package.properties as given below:
  • portal-dependency-jars=\   commons-fileupload.jar,\ commons-lang.jar


8) Project structure:


9) No more steps :) deploy it and You will see below screen just add something in editor and press show button. It will show same content below show button. i have included this functionality because you could get idea about how we can get content from editor and show it on the page.
    Next post we gonna see how to make simple jcarousal in zk + liferay portlet... GOOD DAY...

Tuesday 7 May 2013

Internationalization in Liferay + Zk Portlet


Internationalization in Zk+liferay Portlet

We have already created one simple portlet. Now we gonna build one by one functionality on top of that.


In this post we gonna see how internationalization could be done in zk+liferay portlet.

So you can refer earlier post for making a simple portlet.

For adding internationalization follow below steps:

1)Create zk-label.properties file and also create /docroot/properties folder and put zk-label.properties file in that folder which you have created.

 Content of zk-label.properties:

 #--------------------#  
 # Label for zkdemo #  
 #--------------------#  
 username=Username  
 password=Password  
 message=Available Language : ${number}  

2)Add below entry in zk.xml under <zk> tag.

  <system-config>  
        <label-location>/properties/zk-label.properties</label-location>  
   </system-config>  

3) Now You can refer this key-value like pair from .zul page.
edit view.zul file as given below:
 <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c" ?>  
 <zk>  
  <zscript><![CDATA[  
     String number = "10";  
   ]]></zscript>  
   <grid id="demoGrid" width="300px">  
     <rows>  
       <row>  
         <!-- Using The Tag Lib -->  
         ${c:l('username')}<textbox hflex="1"/>  
       </row>  
       <row>  
         <!-- Using EL implicit object labels -->  
         *${labels.password} 1 <textbox type="password" hflex="1"/>  
       </row>  
       <row>  
         <!-- Using The Java Way -->  
         <label id="pwd" /><textbox type="password" hflex="1"/>  
       </row>  
     </rows>  
     <foot>  
       <!-- Properties can get the variable in the page -->  
       <footer style="text-align:right;" span="2"><label value="${c:l('message')}" /></footer>  
     </foot>  
   </grid>  
    <zscript><![CDATA[           
     import org.zkoss.util.resource.Labels; //Labels utility included the international functionality  
     pwd.setValue("*" + Labels.getLabel("password") + " 2" );  
   ]]></zscript>  
 </zk>  

Here in view.zul I have given different way of referring properties key now just deploy it and its ready to go..


Structure of the project:

You can see added zk-label.properties file in our project.



Screenshot-> what we have done:




Now If You change the content of the zk-label.properties as Below:

 #--------------------#  
 # Label for zkdemo #  
 #--------------------#  
 username=उपयोगकर्ता नाम  
 password=पासवर्ड  
 message=भाषा उपलब्ध : ${number}  

You will see like:



In next post -> how could we integrate ck editor in this portlet !!?... GOOD DAY

Monday 6 May 2013

Explore The Power Of ZK + Liferay Integration

Zk Liferay Integration

 Hi guys,

Zk, the best open source Java framework for building enterprise web and mobile apps.You can explore it here ZK. Liferay Portal is the leading open source portal for the enterprise, offering content management, collaboration, and social out-of-the-box.

One can develop sites with the this two powerful platforms with rich interface as simple and fast as authoring HTML pages.

Just check it out what you can do with this.... You will love it :)

So lets roll....

I have used Liferay 6.1  and ZK 6.0.1  for this demo portlet. In which I have include all the functionality which can be useful to web developers like ckeditor, internationalization,CRUDE operation that kind of stuffs ...but I will include that after making one simple zk-portlet, so it couldn't become hectic :).
Oh yes I'll also share my own problems and of course its solutions :) which i have faced while integration process.

  1. We need Liferay IDE for that you can refer this link Liferay IDE.
  2. Install zk-Plugin in IDE also refer this link for zul page detection in IDE.
  3. Create Liferay portlet.
  • Create new Liferay project.
  • Select Liferay MVC portlet option and click on finish.

      

  • ZK related configurations
  • Edit \WEB-INF\web.xml file.

 <?xml version="1.0" encoding="UTF-8"?>   
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">   
  <display-name>ZK-Sample-portlet</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>zkLoader</servlet-name>   
     <url-pattern>*.svg</url-pattern>   
   </servlet-mapping>   
   <servlet-mapping>   
     <servlet-name>zkLoader</servlet-name>   
     <url-pattern>*.xml2html</url-pattern>   
   </servlet-mapping>   
   <servlet-mapping>   
     <servlet-name>auEngine</servlet-name>   
     <url-pattern>/zkau/*</url-pattern>   
   </servlet-mapping>   
   <session-config>   
    <session-timeout>30</session-timeout>   
   </session-config>   
  <jsp-config>   
    <taglib>   
      <taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>   
      <taglib-location>   
        /WEB-INF/tld/liferay-portlet.tld   
      </taglib-location>   
    </taglib>   
  </jsp-config>   
 </web-app>  

  • Edit below zk.xml file to /WEB-INF dir
 <?xml version="1.0" encoding="UTF-8"?>  
 <zk>  
      <library-property>  
     <name>org.zkoss.zul.progressbox.position</name>  
     <value>center,center</value>  
   </library-property>  
   <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>  
   <library-property>  
      <name>org.zkoss.theme.preferred</name>  
      <value>sapphire</value>  
   </library-property>  
   <system-config>  
        <label-location>/properties/zk-label.properties</label-location>  
   </system-config>  
   <error-page>  
        <exception-type>java.lang.Throwable</exception-type>    
        <location>/zul/error.zul</location>    
      </error-page>  
   <session-config>  
        <device-type>ajax</device-type>  
        <timeout-message>Session timeout. Please reload the page.</timeout-message>  
      </session-config>  
 </zk>  

  • Update /WEB-INF/liferay-portlet.xml file as per given below.
 <?xml version="1.0"?>  
 <!DOCTYPE liferay-portlet-app PUBLIC "-//Liferay//DTD Portlet Application 6.1.0//EN" "http://www.liferay.com/dtd/liferay-portlet-app_6_1_0.dtd">  
   <liferay-portlet-app>   
     <portlet>   
       <portlet-name>zk-hello-world</portlet-name>   
       <icon>/icon.png</icon>   
       <instanceable>false</instanceable>   
       <header-portlet-css>/css/main.css</header-portlet-css>   
       <header-portlet-javascript>/zkau/web/js/zk.wpd</header-portlet-javascript>   
       <footer-portlet-javascript>/js/main.js</footer-portlet-javascript>   
       <css-class-wrapper>zk-hello-world-portlet</css-class-wrapper>  
     </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>  

  • Update /WEB-INF/portlet.xml as per given below  
 <?xml version="1.0"?>  
 <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">  
      <portlet>  
           <portlet-name>zk-hello-world</portlet-name>  
           <display-name>ZK Hello World</display-name>  
            <portlet-class>com.liferay.zk.ZKPortlet</portlet-class>   
           <init-param>   
       <name>zk_page_view</name>   
       <value>/zul/view.zul</value>   
     </init-param>   
     <init-param>   
       <name>zk_page_edit</name>   
       <value>/zul/edit.zul</value>   
     </init-param>   
     <expiration-cache>0</expiration-cache>   
     <supports>   
       <mime-type>text/html</mime-type>   
       <portlet-mode>VIEW</portlet-mode>   
       <portlet-mode>EDIT</portlet-mode>   
     </supports>  
           <portlet-info>  
                <title>ZK Hello World</title>  
                <short-title>ZK Hello World</short-title>  
                <keywords>ZK Hello World</keywords>  
           </portlet-info>  
           <security-role-ref>  
                <role-name>administrator</role-name>  
           </security-role-ref>  
           <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>  
  

4. Add below ZK libraries in /WEB-INF/lib directory
  • zcommon.jar
  • zel.jar
  • zhtml.jar
  • zk.jar
  • zkbind.jar
  • zkplus.jar
  • zul.jar
  • zweb.jar
  • bsh.jar
  • commons-fileupload.jar
  • commons-io.jar 
5.Create com.liferay.zk.ZKPortlet.java file as mentioned below

 package com.liferay.zk;  
 import java.io.IOException;  
 import javax.portlet.PortletException;  
 import javax.portlet.PortletPreferences;  
 import javax.portlet.PortletRequestDispatcher;  
 import javax.portlet.PortletSession;  
 import javax.portlet.RenderRequest;  
 import javax.portlet.RenderResponse;  
 import org.zkoss.zk.ui.Session;  
 import org.zkoss.zk.ui.http.DHtmlLayoutPortlet;  
 import com.liferay.portal.kernel.util.WebKeys;  
 import com.liferay.portal.theme.ThemeDisplay;  
 /**  
  * The Class ZKPortlet.  
  */  
 public class ZKPortlet extends DHtmlLayoutPortlet {  
      public static final String ZK_EDIT_PAGE = "zk_page_edit";  
      public static final String ZK_VIEW_PAGE = "zk_page_view";  
      private String strViewModePage;  
      private String strEditModePage;  
      public void init() {  
           this.strViewModePage = getInitParameter(ZK_VIEW_PAGE);  
           this.strEditModePage = getInitParameter(ZK_EDIT_PAGE);  
      }  
      @Override  
      protected boolean process(Session sess, RenderRequest request,  
                RenderResponse response, String path, boolean bRichlet)  
                throws PortletException, IOException {  
           setupSessionParameters(sess, request);  
           return super.process(sess, request, response, path, bRichlet);  
      }  
      protected void setupSessionParameters(Session sess, RenderRequest request) {  
           ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);  
           PortletSession portletSession = request.getPortletSession();  
           PortletPreferences prefs = request.getPreferences();  
           sess.setAttribute("SESSION_ID", portletSession.getId());  
           sess.setAttribute("THEME_DISPLAY", themeDisplay);  
           sess.setAttribute("GROUP_ID", themeDisplay.getScopeGroupId());  
           sess.setAttribute("PORTLET_PREFERENCES", prefs);  
           sess.setAttribute("PORTLET_ID", themeDisplay.getPortletDisplay().getId());  
           sess.setAttribute("currentUser", themeDisplay.getUser().getScreenName());  
      }  
      @Override  
      protected void doEdit(RenderRequest request, RenderResponse response)  
                throws PortletException {  
           try {  
                if (this.strEditModePage != null) {  
                     this.dispatch(this.strEditModePage, request, response);  
                } else {  
                     this.doView(request, response);  
                }  
           } catch (IOException ex) {  
                // Exception Handling Code  
           }  
      }  
      @Override  
      protected void doView(RenderRequest request, RenderResponse response)  
                throws PortletException {  
           try {  
                if (this.strViewModePage != null) {  
                     this.dispatch(this.strViewModePage, request, response);  
                }  
           } catch (IOException ex) {  
                // Exception Handling Code  
           }  
      }  
      protected void include(String path, RenderRequest renderRequest,  
                RenderResponse renderResponse) throws IOException, PortletException {  
           try {  
                PortletRequestDispatcher portletRequestDispatcher = getPortletContext().getRequestDispatcher(path);  
                if (portletRequestDispatcher != null) {  
                     portletRequestDispatcher.include(renderRequest, renderResponse);  
                }  
           } catch (IOException ex) {  
                // Exception Handling Code  
           }  
      }  
      private void dispatch(String page, RenderRequest request,  
                RenderResponse response) throws IOException, PortletException {  
           PortletRequestDispatcher objDisp = this.getPortletContext().getRequestDispatcher(page);  
           if (objDisp != null) {  
                objDisp.include(request, response);  
           }  
      }  
 }  

 6. Create /docroot/zul folder and place below zul files in it.
  •  edit.zul
  • error.zul
  • view.zul
 put this content in view.zul

 <zk>  
      <window title="ZK Demo Portlet" border="normal" width="200px">  
           <label value="Hello, World!"></label>  
      </window>  
 </zk>  

like wise error.zul

 <?page id="errorPage" title="Error Page" cacheable="false" language="xul/html" zscriptLanguage="Java" contentType="text/html;charset=UTF-8"?>  
 <?taglib uri="http://www.zkoss.org/dsp/web/core" prefix="c"?>  
 <zk xmlns:html="http://www.w3.org/1999/xhtml"  
   xmlns="http://www.zkoss.org/2005/zul"  
   xmlns:zk="http://www.zkoss.org/2005/zk"  
   xmlns:w="http://www.zkoss.org/2005/zk/client">  
 <window id="wndErr" width="400px" border="normal" mode="modal" closable="true">  
      <caption id ="captErrWnd" label="Error" style="font-weight:Bold;" />  
   <vbox width="390px">   
        <separator />  
        <hbox style="align: center" width="390px">  
       <separator />  
       <image id="iconImg" src="/images/error.png"/>  
       <separator />  
       <separator />  
       <label id="lblErrMessage" value="Error while processing"/>  
     </hbox>  
     <div width="390px" align="center">  
       <button id="btnOK" label="OK" onClick="wndErr.detach()" width="80px" />  
       <button id="btnReload" label="Reload" onClick="Executions.sendRedirect(null)" width="80px" visible="false"/>  
     </div>  
   </vbox>  
 </window>  
 </zk>  
  
and edit.zul


 <zk>  
      <window title="ZK Demo Portlet" border="normal" width="200px">  
           <label value="Hello, World!"></label>  
      </window>  
 </zk>  

Structure of the project

 

All things done just start your server and deploy it.

put this portlet from add menu of liferay portal and you will see below screen.

And its done...now we can add more functionality to this portlet like ckeditor ,CRUD operation with liferay services and also internationalization.GOOD DAY