Saturday, October 24, 2009

STEP 10: Create an ICEfaces Portlet in Liferay

Create ICEfaces Project in NetBeans

File | New Project
  • Categories: Java Web

  • Projects: Web Application
Next
  • Project Name: ICEfacesLiferay001
Next
  • Server: Liferay 5.2.3 (Tomcat 6.0.18)

  • Java EE Version: Java EE 5

  • Context Path: /ICEfacesLiferay001
Next
  • Select the frameworks you want to use in your web application.

    • Checked: ICEfaces

  • ICEfaces Configuration...

    • Checked: Validate XML

    • Checked: Synchronous Update

    • Checked: Concurrent DOM View

    • Un-Checked: welcomeICEfaces.jspx

    • Un-Checked: welcomeICEfaces.xhtml (Facelets Only)
Finish


Create JSF Portlet Page

Projects (tab) | Expand ICEfacesLiferay001 | Right Click WebPages | New | Other
  • Categories: Java Server Faces

  • File Types: JSF JSP Page
Next
  • JSP File Name: MyIcePortlet_view

  • Project: ICEfacesLiferay001

  • Location: WebPages

  • Folder: (blank)

  • Created File: (automatically populated)

  • Options: JSP Document (XML Syntax)
Finish

A new file called MyIcePortlet_view.jspx will be created. Replace the entire contents of this file with the following. Then save the new file.

<?xml version="1.0" encoding="UTF-8"?>
<f:view xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ice="http://www.icesoft.com/icefaces/component">
    <html>

        <head>
            <title>VIEW: My ICEfaces Portlet</title>
        </head>

        <body>
            <ice:portlet>
                <ice:form id="iceform">

                    VIEW: Hello World ICEfaces Portlet

                </ice:form>
            </ice:portlet>
        </body>

    </html>
</f:view>


Create portlet.xml

Projects (tab) | Expand ICEfacesLiferay001 | Expand Web Pages | Expand WEB-INF | Right Click WebPages | New | Other
  • Categories: XML

  • File Types: XML Document
Next
  • File Name: portlet

  • Project: ICEfacesLiferay001

  • Folder: web/WEB-INF

  • Created File: (automatically populated)
Next
  • Selected: Well-formed Document
Finish

A new file called portlet.xml will be created. Replace the entire contents of this file with the following. Then save the new file.

<?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>MyIcePortlet</portlet-name>
        <display-name>MyIcePortlet</display-name>
        <portlet-class>com.icesoft.faces.webapp.http.portlet.MainPortlet</portlet-class>

        <init-param>
            <name>com.icesoft.faces.portlet.viewPageURL</name>
            <value>/MyIcePortlet_view.iface</value>
        </init-param>

        <supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
        </supports>

        <portlet-info>
            <title>ICEfaces: MyIcePortlet</title>
            <short-title>MyIcePortlet</short-title>
            <keywords>ICEfaces My Ice Portlet</keywords>
        </portlet-info>
        
    </portlet>

</portlet-app>


Update liferay-portlet.xml

Projects (tab) | Expand ICEfacesLiferay001 | Expand Web Pages | Expand WEB-INF | Double Click liferay-portlet.xml

Edit liferay-portlet.xml and add the the <portlet> element as shown in bold, below. Then save the file.

<?xml version="1.0" encoding="UTF-8"?>
<!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>MyIcePortlet</portlet-name>
        <instanceable>true</instanceable>
        <render-weight>1</render-weight>
        <ajaxable>false</ajaxable>
    </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 liferay-display.xml

Projects (tab) | Expand ICEfacesLiferay001 | Expand Web Pages | Expand WEB-INF | Double Click liferay-display.xml

Edit liferay-display.xml and update the the <category> element as shown in bold, below. Then save the file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE display PUBLIC "-//Liferay//DTD Display 5.2.0//EN" "http://www.liferay.com/dtd/liferay-display_5_2_0.dtd">
<display>

    <category name="ICEfaces Portlets">
        <portlet id="MyIcePortlet"/>
    </category>

</display>


Update web.xml

Projects (tab) | Expand ICEfacesLiferay001 | Expand Web Pages | Expand WEB-INF | Double Click web.xml

Edit web.xml. Search for <servlet-name>Faces Servlet</servlet-name> that has the element <url-pattern>/faces/*</url-pattern>. Replace <url-pattern>/faces/*</url-pattern> with <url-pattern>*.jspx</url-pattern> as shown in bold, below. Then save the file.

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>

        <url-pattern>*.jspx</url-pattern>

    </servlet-mapping>


Test

In NetBeans...
  • Click on the triangular green Run Main Project icon below the menu bar.

  • A browser window will automatically open. If the window does not open, go to http://localhost:8080/web/guest/ in your web browesr.

In the web browser...
  • Click on the Login as bruno link in the Current Users portlet.

  • Hover over Welcome Bruno Admin! at the top right.

  • Click Add Application.

  • The Add Application portlet will appear.

  • Click on ICEfaces Portlets in the The Add Application portlet to expand the node.

  • Click Add next to ICEfaces: MyIcePortlet.

  • The ICEfaces: MyIcePortlet will appear.

In the web browser...
  • Verify that the portlet is displayed.

  • Click the Remove (X) icon at the top right of the ICEfaces: MyIcePortlet portlet.

  • Are you sure you want to remove this component? OK

  • Hover over Welcome Bruno Admin! at the top right.

  • Click Sign Out.

In NetBeans...
  • On the Output panel, click the Stop Server (X) icon.

17 comments:

  1. It might be possibly save a little work on step 10 if you added the "Portlet Support" framework in addition to the ICEfaces framework when creating the Web Application. This will create the portlet.xml and liferay-portlet.xml files for you.

    Also, when configuring the ICEfaces framework, you should consider un-checking Synchronous Update since asynchronous updates are a major benefit of using ICEfaces for portlet development. Concurrent DOM View should be un-checked unless your application will need to support multiple windows or tabs accessing the same server-side DOM.

    Finally, you could leave welcomeICEfacesjspx checked and use this later in the step instead of creating a new file.

    Great post! Thanks for sharing the information.
    - JB

    ReplyDelete
  2. I followed this steps and I always got errors. java.lang.NullPointerException at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:158)

    Is there something I need to configure? I did followed every xml that you changed here.

    ReplyDelete
  3. JB,

    I noticed that "liferay-portal.xml" is automatically created when you select "Liferay 5.2.3 (Tomcat 6.0.18)" server when creating a Portal project. So you are suggesting that adding Portal Support up front will also create the "portlet.xml" file automatically?

    Also, I had some issues when I un-checked "Synchronous Update" and un-checked "Concurrent DOM View". I will try it again.

    Thanks for your feedback.

    ReplyDelete
  4. Isay,

    I tried to include every step starting with a clean environment. I have tried these steps a few times, and I did not encounter the java.lang.NullPointerException you ran into. Can you share a little information about your environment? What OS are you running on? What version of ICEfaces are you usng? What version of NetBeans are you using? Etc.?

    Thanks,
    PS5000

    ReplyDelete
  5. Hi, My OS is XP. My NetBeans is 6.7. My IceFaces portlet is now working. I just included configurations in the web.xml. And then it worked.

    BTW, JB is right, the portlet and liferay-portlet.xml are autogenerated in Netbeans if you have Portal Portlet Plugin in it. :)

    Anyway, Thanks for this post, it helped me a lot.

    -Isay

    ReplyDelete
  6. Isay,

    I'm glad it helped. When I get a chance, I will update the instructions to:
    - install the NetBeans Portlet Plugin
    - remove manual creation of portlet.xml

    Great tip guys! Thanks.

    PS5000

    ReplyDelete
  7. Hi I followed the steps above to create the iceface portlet. However when I deployed the portlet into liferay it gets unregistered straight away. When I turn on the log4j in tomcat (6.x) it says java.lang.NoClassDefFoundError: javax/faces/context/FacesContextFactory but when I check the WEB-INF/lib folder the jsf-api.jar which contain that class already there? Any clue? :(

    ReplyDelete
  8. Brian,

    Right-click on your project. Select Properties. Click on Libraries. I have the following listed and Checked:
    - JSF 1.2_13 RI Run-Time
    - ICEFaces JSF1.1/1.2 Run-Time Support
    - ICEfaces Run-Time 1.8.2

    Do you have these listed and Checked?

    ReplyDelete
  9. I can only assume this is some type of javascript lockup. Also, I hadn't noticed this problem prior to ICEfaces 1.7RC1 In order to reproduce, follow these steps:

    1. Download and Install the Liferay 4.4.2 + Tomcat 6.0.16 bundle
    2. Run the bundle, which will create a $HOME/liferay/deploy folder
    3. Download the sample-icefaces-jsf-1.1-myfaces-jsp-portlet-4.4.1.1.war attached to this ticket and copy to $HOME/liferay/deploy
    4. Download the sample-icefaces-jsf-1.1-sun-facelets-portlet-4.4.1.1.war attached to this ticket and copy to $HOME/liferay/deploy
    5. Start IE7 (that's the key, since I can't reproduce this with FireFox or Safari)
    6. Login as test@liferay.com with password test
    7. Position the mouse over the "Welcome" dock in the upper right hand corner
    8. Navigate to "My Places > My Community > Private Pages"
    9. Add a page named "ICE MyFaces"
    10. Add a page named "ICE Sun"
    11. Click on the "ICE MyFaces" tab, and add the "Sample ICEfaces JSF 1.1 MyFaces JSP" portlet from the "Samples" category
    12. Click on the "ICE Sun" tab, and add the "Sample ICEfaces JSF 1.1 Sun Facelets" portlet from the "Samples" category
    13. Start tabbing through the fields of the portlet. Most of the fields are REQUIRED, and if you tab-out without entering anything you should see D2D show a FacesMessage next to each field.

    vitamine b12

    ReplyDelete
  10. I followed this step but I couldn't build my project successfully. I got the following errors:

    Deployment error:
    null


    See the server log for details.
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:224)
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:132)
    at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:103)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:278)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:497)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
    Caused by: java.lang.NullPointerException
    at org.netbeans.modules.portalpack.servers.core.PSDeployerImpl.deploy(PSDeployerImpl.java:79)
    at org.netbeans.modules.portalpack.servers.core.impl.j2eeservers.tomcat.TomcatIncrementalDeployment.initialDeploy(TomcatIncrementalDeployment.java:87)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.deploy(TargetServer.java:616)
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:189)
    ... 17 more

    Am I wrong somewhere? I did follow every xml that you changed here. Does anybody have a solution to it?

    ReplyDelete
  11. This is the ever best tutorial, Thanks PS5000

    ReplyDelete
  12. i follow each step on your blog, but when i deploy/run i got this following error

    In-place deployment at D:\netbeansportlet\ICEFaces001\build\web
    Deployment error:
    null
    See the server log for details.
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:224)
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:132)
    at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:103)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:278)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:497)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
    Caused by: java.lang.NullPointerException
    at org.netbeans.modules.portalpack.servers.core.PSDeployerImpl.deploy(PSDeployerImpl.java:79)
    at org.netbeans.modules.portalpack.servers.core.impl.j2eeservers.tomcat.TomcatIncrementalDeployment.initialDeploy(TomcatIncrementalDeployment.java:87)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.deploy(TargetServer.java:616)
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:189)
    ... 17 more
    BUILD FAILED (total time: 0 seconds)

    ReplyDelete
  13. hi,
    i am facing a problem when using datatable and paginatar of icefaces, it do not generate any request on the action of any sorting column or paging links.

    ReplyDelete
  14. Hi, I'm having the same trouble

    In-place deployment at D:\Mis Documentos\NetBeansProjects\prueba002\build\web
    D:\Mis Documentos\NetBeansProjects\prueba002\nbproject\build-impl.xml:577:
    Deployment error:
    null
    See the server log for details.
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:205)
    at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:103)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    at sun.reflect.GeneratedMethodAccessor166.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:278)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:498)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:151)
    Caused by: java.lang.NullPointerException
    at org.netbeans.modules.portalpack.servers.core.PSDeployerImpl.deploy(PSDeployerImpl.java:79)
    at org.netbeans.modules.portalpack.servers.core.impl.j2eeservers.sunappserver.SunAppIncrementalDeployment.initialDeploy(SunAppIncrementalDeployment.java:88)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.deploy(TargetServer.java:623)
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:170)
    ... 16 more
    GENERACIÓN INCORRECTA (total time: 2 seconds)

    ReplyDelete
  15. Hey,
    thanks for the great Tutorial.
    I also had the problem with deployment error: null
    NullPointerException

    I solved it that way:
    go to services -> server -> rightklick on liferay -> properties -> uncheck Directory Deployment Enabled

    now it works fine.

    ReplyDelete
  16. Excellent work ............ It means u can try now eclipse-Liferay IDE 1.0 ,please make a post for it also......
    Thanks
    Mr.Bhatia

    ReplyDelete
  17. I followed the same instruction which are posted here, but have some errors given as below, so if possible then tell me how to resolve this error...



    In-place deployment at C:\Users\dell\Documents\NetBeansProjects\ICEfacesLiferay001\build\web
    C:\Users\dell\Documents\NetBeansProjects\ICEfacesLiferay001\nbproject\build-impl.xml:731:
    Deployment error:
    null
    See the server log for details.
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:209)
    at org.netbeans.modules.j2ee.ant.Deploy.execute(Deploy.java:106)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
    at sun.reflect.GeneratedMethodAccessor145.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284)
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539)
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:154)
    Caused by: java.lang.NullPointerException
    at org.netbeans.modules.portalpack.servers.core.PSDeployerImpl.deploy(PSDeployerImpl.java:79)
    at org.netbeans.modules.portalpack.servers.core.impl.j2eeservers.tomcat.TomcatIncrementalDeployment.initialDeploy(TomcatIncrementalDeployment.java:87)
    at org.netbeans.modules.j2ee.deployment.impl.TargetServer.deploy(TargetServer.java:635)
    at org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment.deploy(Deployment.java:174)
    ... 16 more
    BUILD FAILED (total time: 13 seconds)

    ReplyDelete