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.

STEP 9: Add Tomcat to NetBeans

These are instructions to add the standalone Tomcat server to NetBeans. Netbeans comes bundled with an older version of Tomcat, but this is how to add the latest version.


Create New Server

In NetBeans...

Tools | Servers | Add Server
  • Server: Tomcat 6.0

  • Name: Tomcat 6.0.20
Next
  • Server Location : /usr/local/apache-tomcat-6.0.20

  • User Name: admin

  • Password: adminadmin

  • Checked: Create user if it does not exist
Finish | Close



Test

In NetBeans...

Services (tab) | Servers | Right Click: Tomcat 6.0.20 | Start

In a web browser, go to...

http://localhost:8080

In NetBeans...

On the Output panel, click the Stop Server icon.

STEP 8: Install Tomcat

These are instructions to install the standalone Tomcat. This Tomcat should be installed after Liferay bundled with Tomcat is installed.

DOWNLOAD: apache-tomcat-6.0.20.tar.gz
FROM URL: http://tomcat.apache.org/


Install

Open a terminal window, and enter the following commands. Replace [download location] with the directory where you downloaded the software. Note that your login id will be added to the users group, and that access to the Tomcat server installation will be granted to members of the users group.

$ cd [download location]
$ sudo adduser `whoami` users
$ newgrp users
$ sudo tar -zxvf apache-tomcat-6.0.20.tar.gz -C /usr/local
$ sudo chown -R root:users /usr/local/apache-tomcat-6.0.20
$ sudo chmod -R g=u /usr/local/apache-tomcat-6.0.20

STEP 7: Add Liferay (Glassfish) to NetBeans

These are instructions to add the Liferay portal server (running on Glassfish) to NetBeans.


Create New Server

In NetBeans...

Tools | Servers | Add Server
  • Server: Liferay Portal Server 5.1.x/5.2.x

  • Name: Liferay 5.2.3 (GlassFish 3)
Next
  • Server Type: GlassFish / Sun Java System AppServer

  • GlassFish Home: /usr/local/liferay-portal-5.2.3/glassfish

  • Domain Dir: /usr/local/liferay-portal-5.2.3/glassfish/domains/domain1

  • Domain: domain1

  • User Name: admin

  • Password: adminadmin

  • Http Port: 8080

  • Admin Port: 4848
Next
  • Portal Context: /

  • Portal Deploy Dir: /usr/local/liferay-portal-5.2.3/glassfish/domains/domain1/applications/liferay-portal

  • Checked: Directory Deployment Enabled
Finish
  • Auto Deploy Dir: /usr/local/liferay-portal-5.2.3/deploy
Apply | Close



Test

In NetBeans...

Services (tab) | Servers | Liferay 5.2.3 (GlassFish 3) | Start

In a web browser, go to...

http://localhost:8080/web/guest

In NetBeans...

On the Output panel, click the Stop Server icon.

STEP 6: Add Liferay (Tomcat) to NetBeans

These are instructions to add the Liferay portal server (running on Tomcat) to NetBeans.

Create New Server

In NetBeans...

Tools | Servers | Add Server
  • Server: Liferay Portal Server 5.1.x/5.2.x
  • Name: Liferay 5.2.3 (Tomcat 6.0.18)

Next
  • Server Type: Tomcat 6.x
  • Catalina Home: /usr/local/liferay-portal-5.2.3/tomcat-6.0.18
  • Catalina Base: /usr/local/liferay-portal-5.2.3/tomcat-6.0.18
  • Java Home: JDK 1.6 (Default)(/usr/lib/jvm/java-6-sun)
  • Http Port: 8080
  • Debug Port: 11589

Next
  • Portal Context: /
  • Portal Deploy Dir: /usr/local/liferay-portal-5.2.3/tomcat-6.0.18/webapps/ROOT
  • Checked: Directory Deployment Enabled
  • Un-Checked: Run in Developer Mode

Finish
  • Auto Deploy Dir: /usr/local/liferay-portal-5.2.3/deploy

Apply | Close


Test

In NetBeans...

Close the Start page if it is open.

Services (tab) | Servers | Liferay 5.2.3 (Tomcat 6.0.18) | Start

In a web browser, go to...

http://localhost:8080/web/guest

In NetBeans...

In the Output panel, click the Stop Server icon.

STEP 5: Install Liferay (Glassfish)

These are instructions to install Liferay with Glassfish.


DOWNLOAD: liferay-portal-glassfish-5.2.3.zip
FROM URL: http://www.liferay.com/web/guest/downloads/portal



Install

Open a terminal window, and enter the following commands. Replace [download location] with the directory where you downloaded the software. Note that your login id will be added to the users group, and that access to the liferay server installation will be granted to members of the users group.

$ cd [download location]
$ sudo adduser `whoami` users
$ newgrp users
$ sudo unzip -o liferay-portal-glassfish-5.2.3.zip -d /usr/local
$ sudo chown -R root:users /usr/local/liferay-portal-5.2.3
$ sudo chmod -R g=u /usr/local/liferay-portal-5.2.3
$ cd /usr/local/liferay-portal-5.2.3/glassfish/bin/; for file in `ls -1 | grep -v "\\."`; do sudo chmod ug+x $file; done; cd -



Test

Open a new terminal window, and enter the following commands.

$ cd /usr/local/liferay-portal-5.2.3/glassfish/bin
$ ./startserv


In a web browser window, go to...

http://localhost:8080/web/guest

In the terminal window...

CTRL-C

STEP 4: Install Liferay (Tomcat)

These are instructions to install Liferay with Tomcat.

DOWNLOAD: liferay-portal-tomcat-6.0-5.2.3.zip
FROM URL: http://www.liferay.com/web/guest/downloads/portal



Install

Open a terminal window, and enter the following commands. Replace [download location] with the directory where you downloaded the software. Note that your login id will be added to the users group, and that access to the liferay server installation will be granted to members of the users group.

$ cd [download location]
$ sudo adduser `whoami` users
$ newgrp users
$ sudo unzip -o liferay-portal-tomcat-6.0-5.2.3.zip -d /usr/local/
$ sudo chown -R root:users /usr/local/liferay-portal-5.2.3
$ sudo chmod -R g=u /usr/local/liferay-portal-5.2.3



Test

Open a new terminal window...

$ cd /usr/local/liferay-portal-5.2.3/tomcat-6.0.18/bin
$ ./catalina.sh run


If a web browser window does not open automatically, go to...

http://localhost:8080/web/guest

In the terminal window...

CTRL-C