JBoss Portal 2.4

Reference Guide

Thomas Heute

Roy Russo

Boleslaw Dawidowicz

Release 2.4 "Devil"

July 2006


Table of Contents

JBoss Portal - Overview
Feature List
Target Audience
Acknowledgements
1. System Requirements
1.1. Minimum System Requirements
1.2. Supported Operating Systems
1.3. JBoss Application Server
1.4. Database
1.5. Source building
2. Installation
2.1. Installing from Bundled Download
2.1.1. Installing the Bundle
2.2. Installing from Binary Download
2.2.1. Setting up your environment
2.2.1.1. Getting the Binary
2.2.1.2. Application Server Setup
2.2.1.3. Database Setup
2.2.1.4. DataSource Configuration
2.2.2. Deploying JBoss Portal
2.3. Installing from Sources
2.3.1. Getting the Sources
2.3.2. Setting up your environment
2.3.2.1. Application Server Setup
2.3.2.2. Operating System Environment Setting
2.3.2.3. Database Setup
2.3.2.4. DataSource Configuration
2.3.3. Building/Deploying from Sources
3. Customizing your installation
3.1. Changing the port
3.2. Changing the context path
3.3. Forcing the DB dialect
3.3.1. DB Dialect settings for the portal core
3.3.2. DB Dialect settings for the CMS component
4. Upgrading 2.2 - 2.4
4.1. Migrating the Database
4.1.1. Database Requirements/Preparation
4.1.2. DataSource Requirements/Preparation
4.1.3. Obtaining the Migration Application
4.1.3.1. Downloading binary
4.1.3.2. Building from source
4.1.4. Deploying the Migration Application
4.1.5. Running the Migration Application
4.1.6. Final steps
4.2. Migrating Portlet Descriptors
4.2.1. Car Demo Portlet example
4.2.2. Updating Car Demo Portlet descriptors
5. Portlet Primer
5.1. JSR 168 Overview
5.1.1. Portal Pages
5.1.2. Rendering Modes
5.1.3. Window States
5.1.4. Section Status
5.2. Tutorials
5.2.1. Deploying your first portlet
5.2.1.1. Introduction
5.2.1.2. Package Structure
5.2.1.3. The Portlet Class
5.2.1.4. The Application Descriptors
5.2.1.5. Building your portlet
5.2.1.6. Deploying your portlet
5.2.2. A Simple JSP Portlet
5.2.2.1. Introduction
5.2.2.2. Package Structure
5.2.2.3. The Portlet Class
5.2.2.4. The Application Descriptors
5.2.2.5. JSP files and the portlet taglib
5.2.2.6. Building your portlet
5.2.2.7. Deploying your portlet
5.2.3. A Simple JSF Portlet
5.2.3.1. Introduction
5.2.3.2. Package Structure
5.2.3.3. The Application Descriptors
5.2.3.4. The JSP files
5.2.3.5. Building your portlet
5.2.3.6. Deploying your portlet
6. XML Descriptors
6.1. Portlet Descriptors
6.1.1. *-object.xml
6.1.2. portlet-instances.xml
6.1.3. jboss-portlet.xml
6.1.3.1. Injecting Header Content
6.1.3.2. Injecting Services in the portlet context
6.1.3.3. Portlet Session Replication in a Clustered Environment
6.1.4. portlet.xml
6.2. JBoss Portal Descriptors
6.2.1. Datasource Descriptor (portal-*-ds.xml)
6.2.1.1. Obtaining Datasource Descriptors Binary releases
6.2.1.2. Building Datasource Descriptors from Source
6.2.2. Portlet Debugging (jboss-portal.sar/conf/config.xml)
6.3. Descriptor Examples
6.3.1. Defining a new portal page
6.3.2. Defining a new portal instance
7. Portal urls
7.1. Introduction
7.2. Acessing a portal
7.3. Accessing a page
7.4. Accessing CMS Content
8. Clustering Configuration
8.1. Introduction
8.2. Considerations
8.3. JBoss Portal Clustered Services
8.3.1. Portal Session Replication
8.3.2. Hibernate clustering
8.3.3. Identity clustering
8.3.4. CMS clustering
8.4. Setup
8.5. Portlet Session Replication
8.5.1. JBoss Portal configuration
8.5.2. Portlet configuration
8.5.3. Limitations
9. Web Services for Remote Portlets (WSRP)
9.1. Introduction
9.2. Deploying JBoss Portal's WSRP services
9.3. Making a portlet remotable
9.4. Accessing JBoss Portal's WSRP Producer from a remote Consumer
9.5. Consuming remote WSRP portlets in JBoss Portal
9.5.1. Overview
9.5.2. Required configuration information
9.5.3. Optional configuration
9.5.4. Examples
10. Security
10.1. Securing Portal Objects
11. CMS Portlet
11.1. Introduction
11.2. Features
11.3. CMS Configuration
11.3.1. Welcome page
11.3.2. Service Configuration
11.3.2.1. Tuning Jackrabbit
11.3.2.2. Changing the url under which the content should be accessible
11.3.3. Configuring the Content Store Location
11.3.3.1. 100% Filesystem Storage
11.3.3.2. 100% Database Storage
11.3.3.3. Mixed Storage
11.4. Localization Support
11.5. CMS Service
11.5.1. CMS Interceptors
11.5.2. CMS Cache
12. Layouts and Themes
12.1. Overview
12.2. Layouts
12.2.1. How to define a Layout
12.2.2. How to use a Layout
12.2.2.1. Declarative use
12.2.2.2. Programatic use
12.2.3. Where to place the Descriptor files
12.2.4. How to connect a Layout to a Layout Strategy
12.2.5. Layout JSP-tags
12.3. Layout Strategy
12.3.1. What is a Layout Strategy
12.3.2. How can I use a Layout Strategy
12.3.2.1. Define a Strategy
12.3.2.2. Specify the Strategy to use
12.3.3. Linking the Strategy and the Layout
12.4. RenderSets
12.4.1. What is a RenderSet
12.4.2. How is a RenderSet defined
12.4.3. How to specify what RenderSet to use
12.5. Themes
12.5.1. What is a Theme
12.5.2. How to define a Theme
12.5.3. How to use a Theme
12.5.4. How to write your own Theme
12.6. Other Theme Functionalities and Features
12.6.1. Content Rewriting and Header Content Injection
12.6.2. Declarative CSS Style injection
12.6.3. Disabling Portlet Decoration
12.7. Theme Style Guide (based on the Industrial theme)
12.7.1. Overview
12.7.2. Main Screen Shot
12.7.3. List of CSS Selectors
13. Troubleshooting and FAQ
13.1. Troubleshooting and FAQ

Release 2.4 "Devil"

July 2006

JBoss Portal - Overview

Many IT organizations look to achieve a competitive advantage for the enterprise by improving business productivity and reducing costs. Today's top enterprises are realizing this goal by deploying enterprise portals within their IT infrastructure. Enterprise portals simplify access to information by providing a single source of interaction with corporate information. Although today?s packaged portal frameworks help enterprises launch portals more quickly, only JBoss Portal can deliver the benefits of a zero-cost open source license combined with a flexible and scalable underlying platform.

JBoss Portal provides an open source and standards-based environment for hosting and serving a portal's Web interface, publishing and managing its content, and customizing its experience. It is entirely standards-based and supports the JSR-168 portlet specification, which allows you to easily plug-in standards-compliant portlets to meet your specific portal needs. JBoss Portal is available through the business-friendly LGPL open source license and is supported by JBoss Inc. Professional Support and Consulting . JBoss support services are available to assist you in designing, developing, deploying, and ultimately managing your portal environment. JBoss Portal is currently developed by JBoss, Inc. developers, Novell developers, and community contributors.

The JBoss Portal framework and architecture includes the portal container and supports a wide range of features including standard portlets, single sign-on, clustering and internationalization. Portal themes and layouts are configurable. Fine-grained security administration down to portlet permissions rounds out the security model. JBoss Portal includes a rich content management system and message board support.

JBoss Portal Resources:

The JBoss Portal team encourages you to use this guide to install and configure JBoss Portal. If you encounter any configuration issues or simply want to take part in our community, we would love to hear from you in our forums.

Feature List

The following list details features found in this document's related release. For a technical view of our features, view the Project Roadmap and Task List .

Technology and Architecture

  • JEMS: Leverages the power of JBoss Enterprise Middleware Services : JBoss Application Server, JBoss Cache, JGroups, and Hibernate.
  • DB Agnostic: Will work with any RDBMS supported by Hibernate
  • SSO/LDAP: Leverages Tomcat and JBoss single sign on (SSO) solutions.
  • JAAS Authentication: Custom authentication via JAAS login modules.
  • Cacheing: Utilizes render-view caching for improved performance.
  • Clusterable: Cluster support allows for portal state to be clustered for all portal instances.
  • Hot-Deployment: Leverages JBoss dynamic auto deployment features.
  • SAR Installer: Browser-based installer makes installation and initial configuration a breeze.

Supported Standards

  • Portlet Specification and API 1.0 (JSR-168)
  • Content Repository for Java Technology API (JSR-170)
  • Java Server Faces 1.2 (JSR-252)
  • Java Management Extension (JMX) 1.2
  • Web Services for Remote Portlets (WSRP) 1.0 Base Level
  • Full J2EE 1.4 compliance when used with JBoss AS

Portal and Portal Container

  • Multiple Portal Instances: Ability to have multiple Portal instances running inside of one Portal container.
  • IPC Inter-Portlet Communication API enables portlets to create links to other objects such as a page, portal or window .
  • Dynamicity The ability for administrators and users to create and destroy objects such as portlets, pages, portals, themes, and layouts at runtime.
  • Internationalization: Ability to use internationalization resource files for every portlet.
  • Pluggable services: Authentication performed by the servlet container and JAAS make it possible to swap the authentication scheme.
  • Page-based Architecture: Allows for the grouping/division of portlets on a per-page basis.
  • Existing Framework support: Portlets utilizing Struts, Spring MVC, Sun JSF-RI, AJAX, or MyFaces are supported.

Web Services for Remote Portlets

  • WSRP Consumer
    • Support for WSRP Base level (support for service description and markup interfaces)
    • Ability to easily consume portlets from remote producers
    • Seamless integration of WSRP portlets in portal
    • Support for simple registration schemes
    • Simple caching of markup and metadata
  • WSRP Producer
    • Support for WSRP Base level (support for service description and markup interfaces)
    • Local portlets can easily be exposed remotely to WSRP consumers
    • Includes a local WSRP producer to easily test WSRP in Portal ('self' portlet provider)

Themes and Layouts

  • Easily swappable themes/layouts: New themes and layouts containing images can be deployed in WAR archives.
  • Flexible API: Theme and Layout API are designed to separate the business layer from the presentation layer.
  • Per-page layout strategy: Different layouts can be assigned to different pages.

User and Group Functionality

  • User registration/validation: Configurable registration parameters allow for user email validation before activation.
  • User login: Makes use of servlet container authentication.
  • Create/Edit Users: Ability for administrators to create/edit user profiles.
  • Create/Edit Roles: Ability for administrators create/edit roles.
  • Role Assignment: Ability for administrators to assign users to roles.

Permissions Management

  • Extendable permissions API: Allows custom portlets permissions based on role definition.
  • Administrative interface: Allows for permissions assignments to roles at any time for any deployed portlet, page, or portal instance.

Content Management System

  • JCR-compliant: The CMS is powered by Apache Jackrabbit, an open source implementation of the Java Content Repository API.
  • DB or Filesystem store support: Configurable content store to either a filesystem or RDBMS.
  • External Blob Support: Configurable content store allowing large blobs to reside on filesystem and content node references/properties to reside in RDBMS.
  • Versioning support: All content edited/created is autoversioned with a history of edits that can be viewed at any time.
  • Content Serving Search-engine-friendly URLS: http://yourdomain/portal/content/index.html (Does not apply to portlet actions.)
  • No long portal URLS: Serve binaries with simple urls. (http://domain/files/products.pdf)
  • Multiple HTML Portlet instance support: Allows for extra instances of static content from the CMS to be served under separate windows.
  • Directory Support: create, move, delete, copy, and upload entire directory trees.
  • File Functions: create, move, copy, upload, and delete files.
  • Embedded directory-browser: When copying, moving, deleting, or creating files, administrators can simply navigate the directory tree to find the collection they want to perform the action on.
  • Ease-of-use architecture: All actions to be performed on files and folder are one mouse-click away.
  • Full-featured HTML editor: HTML Editor contains WYSIWYG mode, preview functionality, and HTML source editting mode. HTML commands support tables, fonts, zooming, image and url linking, flash movie support, bulleted and numbered list, and dozens more.
  • Editor style-sheet support: WYSIWYG editor displays current Portal style-sheet, for easy choosing of classes.
  • Internationalization Support: Content can be attributed to a specific locale and then served to the user based on his/her browser settings.

Message Boards

  • Instant reply: Instant reply feature, makes for one-click replies to posts.
  • Post quoting: Quote an existing topic and poster within a reply.
  • Flood control: Prevents abuse of multiple posts withing a set configurable time-frame.
  • Category creation: Create a category that contains forums within it.
  • Forum creation: Create a forum and assign it to a specific category.
  • Forum modification: Edit, move, delete forums.
  • Forum and category reordering: Reorder categories and forums in the order you would like them to appear on the page.

Target Audience

Portlet developers, Portal administrators, and those wishing to implement/extend the JBoss Portal framework.

For end-user documentation, please download our User Guide from our documentation page .

Acknowledgements

We would like to thank all the developers that participate in the JBoss Portal project effort.

Specifically,

  1. Thomas Heute, for his help on the first-ever version of JBoss Portal and the corresponding documentation. ;-)
  2. Remy for his help with Tomcat configuration.
  3. Mark Fernandes and Paul Tamaro from Novell, for their hard work in supplying the portal project with usable and attractive themes and layouts.
  4. Kev "kevs3d" Roast for supplying us with two working portlets that integrate existing frameworks in to the portal: Sun JSF-RI and Spring MVC Portlet.
  5. Swarn "sdhaliwal" Dhaliwal for supplying us with the Struts-Bridge, that will allow for existing struts applications to work with the Portal.
  6. Julien Viet for creating a scalable and flexible architecture... and putting up with all of my crazy ideas.

Contributions of any kind are always welcome, you can contribute by providing ideas, filling bug reports, producing some code, designing a theme, writing some documentation, etc... To report a bug please use our Jira system .

Chapter 1. System Requirements

Thomas Heute

Roy Russo

A list of tested versions or reported as working by users, before reporting a problem please make sure that you are using a compatible version.

If you successfully installed JBoss Portal on versions not listed here please let us know so we can add it here.

1.1. Minimum System Requirements

  • JDK 1.4 or higher (1.4.2 is recommended)
  • 512 MB RAM
  • 50 MB hard disk space
  • 400 MHz CPU

1.2. Supported Operating Systems

JBoss Portal is 100% pure Java and therefore interoperable with most operating systems capable of running a Java Virtual Machine (JVM); including Windows, UNIX, and Linux.

1.3. JBoss Application Server

JBoss Portal only works with JBoss Application Server.

Warning

Currently we recommend using JBoss AS 4.0.4.GA, or greater. Previous versions of JBoss Application Server are not supported with JBoss Portal 2.4

1.4. Database

JBoss Portal is Database-Agnostic.

Note

JBoss Portal employs Hibernate as an interface to RDBMS. Most RDBMS supported by Hibernate will work with JBoss Portal.

The following list, outlines known-to-be-working database vendor and version combinations:

  • MySQL 4.x.x (along with the connector 3.0.16)
  • MySQL 5 ( known issue )
  • PostgreSQL 8.x
  • HypersonicSQL
  • Derby
  • Oracle 9 and 10g
  • MSSQL
  • MaxDB

1.5. Source building

The source building mechanism works on Windows, Linux, MacOS X and any 'Unix like' operating system.

Chapter 2. Installation

There are 3 different methods to getting JBoss Portal up and running. The one you choose is up to you, but all result in your being able to run/deploy the best Portal application in the world. ;-)

Note

As of JBoss Portal 2.4-CR1, we have made available pre-configured clustered versions. They are available from the download page , in the same 3 flavors as the non-clustered version. The installation difference, being that they must be deployed in the all configuration in JBoss AS. Read Chapter 8, Clustering Configuration for more details on how to customize your clustered install, once deployed.

2.1. Installing from Bundled Download

This is the easiest and fastest way to get JBoss Portal installed and running. The reason, is that the download bundle contains JBoss Application Server, and JBoss Portal uses the embedded Hypersonic Database.

2.1.1. Installing the Bundle

  • Get the Bundle: The download bundle is available from our download page . Bundles are noted with the 'JBoss Portal + AS' naming convention.

  • Extract the bundle: Extract the zip archive to a directory of your choosing. In windows, we recommend, C:\jboss-X.X.X

  • Start the Server: Go to JBOSS_INSTALL_DIRECTORY/bin and execute run.bat (run.sh, if Linux)

Note

During the first boot (ever), SQL errors in the log, like the one below, can be safely ignored. They are thrown when the portal checks for the existence of the initial tables, before it creates them for you.
16:43:39,234 WARN [JDBCExceptionReporter] SQL Error: -22, SQLState: S0002
16:43:39,234 ERROR [JDBCExceptionReporter] Table not found in statement ...

Point your browser to http://localhost:8080/portal , and you should see the Portal HomePage. You can now login using one of the two default accounts: user/user or admin/admin .

2.2. Installing from Binary Download

The binary download package typically consists of the jboss-portal.sar , documentation (which you are already reading), and a set of preconfigured datasource descriptors that allow JBoss Portal to communicate with a database.

This installation method is preferred by those who already have JBoss Application Server installed.

2.2.1. Setting up your environment

2.2.1.1. Getting the Binary

The binary download is available from our download page .

Once downloaded and extracted, the folder hierarchy should look like this:

We will be using files contained in this download in the further sections, so please download and extract it first.

2.2.1.2. Application Server Setup

Of course you will need to install JBoss Application Server prior to installing JBoss portal, if you didn't do so yet, please install JBoss 4.0.4+ from here .

Warning

Make sure to download the JBoss AS Zip version. DO NOT ATTEMPT to deploy JBoss Portal on the installer version of JBoss AS! We are currently working on aligning the Application installer with JBoss Portal.

2.2.1.3. Database Setup

You will need a database for JBoss Portal to function, you can use any database supported by Hibernate.

  1. Create a new Database: For example purposes we call this new database jbossportal

  2. Grant access rights for a user to your database: You must make sure the user has access to this new DB, as JBoss Portal will need to create the tables and modify data within them.

  3. Deploy your JDBC connector: You must make available a JDBC connector for JBoss Portal to communicate with your database. The connector lib should be placed in JBOSS_INSTALL_DIRECTORY/server/default/lib/*

2.2.1.4. DataSource Configuration

The JBoss Portal download you extracted in Section 2.2.1.1, “Getting the Binary” contains pre-configured datasource descriptors, you can use for most popular RDBMS under the setup directory.

At this point, you should configure the one that suits you best with your Database and JDBC driver.

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
  <local-tx-datasource>
    <jndi-name>PortalDS</jndi-name>
    <connection-url>jdbc:postgresql:jbossportal</connection-url>
    <driver-class>org.postgresql.Driver</driver-class>
    <user-name>portal</user-name>
    <password>portalpassword</password>
  </local-tx-datasource>
</datasources>
                  

Please verify that the username, password, url, and driver-class are correct for your flavor of DB. You can deploy the datasource file by itself to test, in advance.

2.2.2. Deploying JBoss Portal

  1. Deploy: Copy the datasource descriptor file (*-ds.xml) you modified above AND the jboss-portal.sar from the download folder to JBOSS_INSTALL_DIRECTORY/server/default/deploy/.

  2. Start the Server: Go to JBOSS_INSTALL_DIRECTORY/bin and execute run.bat (run.sh, if Linux)

Note

During the first boot (ever), SQL errors in the log, like the one below, can be safely ignored. They are thrown when the portal checks for the existence of the initial tables, before it creates them for you.
16:43:39,234 WARN [JDBCExceptionReporter] SQL Error: -22, SQLState: S0002
16:43:39,234 ERROR [JDBCExceptionReporter] Table not found in statement ...

Point your browser to http://localhost:8080/portal , and you should see the Portal HomePage. You can now login using one of the two default accounts: user/user or admin/admin .

2.3. Installing from Sources

2.3.1. Getting the Sources

There are two ways for you to obtain the JBoss Portal source files:

  • From our download page

  • From CVS, running the following command:

                            cvs -d :pserver:anonymous@anoncvs.forge.jboss.com:/cvsroot/jboss co jboss-portal-2.4
                         

After checking out of CVS or extracting the Source zip, your directory structure should look like this:

2.3.2. Setting up your environment

2.3.2.1. Application Server Setup

Of course you will need to install JBoss Application Server prior to installing JBoss portal, if you didn't do so yet, please install JBoss 4.0.4+ from here .

Warning

Make sure to download the JBoss AS Zip version. DO NOT ATTEMPT to deploy JBoss Portal on the installer version of JBoss AS! We are currently working on aligning the Application installer with JBoss Portal.

2.3.2.2. Operating System Environment Setting

For the build targets to work, you must first set the JBOSS_HOME environment variable in your operating system, to the root directory of the JBoss Application Server installation.

In Windows, this is accomplished by going to Start > Settings > Control Panel > System > Advanced > Environment Variables . Now under the System Variables section, click New . You will be setting the JBOSS_HOME environment variable to the location of your JBoss Application Server installation:

On a Unix-like Operating System, you would accomplish this by typing:

export JBOSS_HOME=/path/to/your/jboss/directory

2.3.2.3. Database Setup

You will need a database for JBoss Portal to function, you can use any database supported by Hibernate.

  1. Create a new Database: For example purposes we call this new database jbossportal

  2. Grant access rights for a user to your database: You must make sure the user has access to this new DB, as JBoss Portal will need to create the tables and modify data within them.

  3. Deploy your JDBC connector: You must make available a JDBC connector for JBoss Portal to communicate with your database. The connector lib should be placed in JBOSS_HOME/server/default/lib/*

2.3.2.4. DataSource Configuration

You will need a valid datasource descriptor, for JBoss Portal to communicate with your database. Having obtained the sources and having set your JBOSS_HOME environment variable ( Section 2.3.2.2, “Operating System Environment Setting” ), you can now have the JBoss Portal build system generate preconfigured datasources for you.

Navigate to JBOSS_PORTAL_HOME_DIRECTORY/core and type:

build datasource

Once complete, the datasource build should produce the following directory and file structure:

At this point, you should configure the one that suits you best with your Database and JDBC driver.

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
  <local-tx-datasource>
    <jndi-name>PortalDS</jndi-name>
    <connection-url>jdbc:postgresql:jbossportal</connection-url>
    <driver-class>org.postgresql.Driver</driver-class>
    <user-name>portal</user-name>
    <password>portalpassword</password>
  </local-tx-datasource>
</datasources>
                  

Please verify that the username, password, url, and driver-class are correct for your flavor of DB.

Now copy your datasource descriptor to JBOSS_HOME/server/default/deploy

2.3.3. Building/Deploying from Sources

To build and deploy the JBoss Portal service, go to JBOSS_PORTAL_HOME_DIRECTORY/build and type:

build deploy

Note

To build the clustered version, you will need to go to JBOSS_PORTAL_HOME_DIRECTORY/build and type:
build main
Then, go to JBOSS_PORTAL_HOME_DIRECTORY/core and type:
build deploy-ha
This will copy the jboss-portal-ha.sar to your all configuration for you.

At the end of the build process, the jboss-portal.sar is copied to JBOSS_HOME/server/default/deploy :

Please verify that your JBOSS_HOME/server/default/deploy directory, contains both necessary files before starting JBoss Application Server.

Start the Server: Go to JBOSS_HOME/bin and execute run.bat (run.sh, if Linux)

Note

During the first boot (ever), SQL errors in the log, like the one below, can be safely ignored. They are thrown when the portal checks for the existence of the initial tables, before it creates them for you.
16:43:39,234 WARN [JDBCExceptionReporter] SQL Error: -22, SQLState: S0002
16:43:39,234 ERROR [JDBCExceptionReporter] Table not found in statement ...

Point your browser to http://localhost:8080/portal , and you should see the Portal HomePage. You can now login using one of the two default accounts: user/user or admin/admin .

Chapter 3. Customizing your installation

Thomas Heute

This section is intended to describe some customization features available in JBoss Portal. If it is not covered here, please view the FAQ chapter at the end of this document or the descriptor chapter ( Section 6.2, “JBoss Portal Descriptors” ) for further documentation on configuration and tuning JBoss Portal.

3.1. Changing the port

It is common to have a server running on the port 80 instead of the default port 8080.

It might be easier to use port forwarding than to change the port manually. Since port forwarding is not always possible, below are the instructions to change the port number manually.

To change it, you need to edit the file $JBOSS_HOME/server/default/deploy/jbossweb-tomcat50.sar/server.xml and change the port value of the HTTP Connector. You can also change the value of the SSL port, by default it is set to 8443. Remember to uncomment the following when you have configured it:

            
      <!-- SSL/TLS Connector configuration using the admin devl guide keystore
      <Connector port="8443" address="${jboss.bind.address}"
           maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"
           emptySessionPath="true"
           scheme="https" secure="true" clientAuth="false"
           keystoreFile="${jboss.server.home.dir}/conf/chap8.keystore"
           keystorePass="rmi+ssl" sslProtocol = "TLS" />
      -->
            
         

You also need to change the port number in the following files for WSRP:

  • jboss-portal.sar/portal-wsrp.sar/default-wsrp.xml
  • jboss-portal.sar/portal-wsrp-client.jar/META-INF/jboss-client.xml (for the producer with the self id.
  • jbossws.sar/META-INF/jboss-service.xml as indicated in JBoss WS' URL rewriting FAQ
  • http-invoker.sar/META-INF/jboss-service.xml

Now you can restart JBoss and use the new port that you defined. On systems like Linux, you need privileges to be able to run a server on a port lower than 1000, starting JBoss on the port 80 as a regular user will not work, for testing you can log as root but is not recommended if the server is public as it could be a security breach in your system.

3.2. Changing the context path

By default, the "main" page of JBoss portal will be accessible at http://localhost:8080/portal/index.html . You may want to change that either to a different name or to http://localhost:8080/index.html .

Note

By default, Tomcat holds on to the root context '/'. Some users have mentioned that you also need to remove the $JBOSS_HOME\server\default\deploy\jbossweb-tomcat55.sar\ROOT.war for the below changes to take effect on restart.

You can accomplish this, with either a deployed jboss-portal.sar or before you build from source:

  • Binary method:

    1. Open JBOSS_INSTALL_DIRECTORY/server/default/deploy/jboss-portal.sar/portal-server.war/WEB-INF/jboss-web.xml

      <?xml version="1.0"?>
      <jboss-web>
         <security-domain>java:jaas/portal</security-domain>
         <context-root>/portal</context-root>
         <replication-config>
            <replication-trigger>SET_AND_GET</replication-trigger>
            <replication-type>SYNC</replication-type>
         </replication-config>
         <resource-ref>
            <res-ref-name>jdbc/PortalDS</res-ref-name>
            <jndi-name>java:PortalDS</jndi-name>
         </resource-ref>
      </jboss-web>

    2. Edit the context-root element to whatever you desire.

      <context-root>/</context-root>

  • Source method: Edit the file $PORTAL_HOME/build/local.properties (You can copy the file $PORTAL_HOME/build/etc/local.properties-example and modify it for your own settings.) and change portal.web.context-root to anything you want.

    Now clean the project (ant clean) then build JBoss portal (ant) and redeploy it for the context path changes to take effect. For build instructions, please see: Section 2.3, “Installing from Sources”

3.3. Forcing the DB dialect

If you encounter that the Hibernate dialect is not working properly and would like to override the default behaviour, follow the instructions contained in this section:

Note

Under most common circumstances, the auto-detect feature should work fine.

3.3.1. DB Dialect settings for the portal core

Modify jboss-portal.sar/conf/hibernate/[module]/hibernate.cfg.xml . A list of supported dialects for Hibernate3, can be found here .

               <?xml version='1.0' encoding='utf-8'?>
               <!DOCTYPE hibernate-configuration PUBLIC
               "-//Hibernate/Hibernate Configuration DTD//EN"
               "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
               <hibernate-configuration>
               <session-factory>
               <property name="connection.datasource">java:PortalDS</property>
               <property name="show_sql">false</property>
               <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
               <property name="cache.use_query_cache">true</property>
               
               <!-- Force the dialect instead of using autodetection -->
               <!--
               <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
               -->
               
               <!-- Mapping files -->
               <mapping resource="conf/hibernate/user/domain.hbm.xml"/>
               </session-factory>
               </hibernate-configuration>               
               

3.3.2. DB Dialect settings for the CMS component

Modify jboss-portal.sar/portal-cms.sar/conf/hibernate/cms/hibernate.cfg.xml . A list of supported dialects for Hibernate3, can be found here .

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
   <session-factory>
      <property name="connection.datasource">java:@portal.datasource.name@</property>
      <property name="show_sql">@portal.sql.show@</property>
      <property name="cache.use_second_level_cache">false</property>
      <property name="cache.use_query_cache">true</property>

      <!-- Force the dialect instead of using autodetection -->
      <!--
      <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
      -->

      <!-- Mapping files -->
      <mapping resource="conf/hibernate/cms/domain.hbm.xml"/>
   </session-factory>
</hibernate-configuration>

Chapter 4. Upgrading 2.2 - 2.4

This chapter addresses migration issues from version 2.2 to 2.4 of JBoss Portal.

4.1. Migrating the Database

JBoss Portal 2.4 comes with dedicated web application for database migration. This application will migrate your existing JBoss Portal 2.2 database data to a new one, for use with JBoss Portal 2.4.

Warning

This migration process should be performed before JBoss Portal 2.4 deployment. Follow the exact steps below, in order, or ugly scary things may happen!

4.1.1. Database Requirements/Preparation

You will need two database instances for this migration process to function:

  • Source JBP 2.2 database from which we migrate portal data. (You should already have this!)

  • Destination JBP 2.4 database to which we migrate portal data.

Before you begin the process you must create a separate database to which the data will be migrated. Note that the Migration Application performs a Hibernate SchemaExport which drops and recreates tables - It is recommended that you backup your database before starting!

For our example, we have two databases... the existing one for JBoss Portal 2.2, and the new (empty) one for JBoss Portal 2.4:

  • JBoss Portal 2.2 DB: jbossportal22

  • JBoss Portal 2.4 DB: jbossportal24

We will use the above database naming, as examples in the next chapter on configuring the datasource.

4.1.2. DataSource Requirements/Preparation

The Migration Application will need access to both databases, while its running. For this reason, we need to make available both JBoss Application Server datasource files.

  1. You should have an existing JBoss Portal 2.2 datasource, portal-ds.xml or portal-*-ds.xml file that looks like this:

                      
                   <?xml version="1.0" encoding="UTF-8"?>
                   <datasources>
                      <local-tx-datasource>
                         <jndi-name>PortalDS</jndi-name>
                         <connection-url>jdbc:mysql://localhost:3306/jbossportal22?useServerPrepStmts=false</connection-url>
                         <driver-class>org.gjt.mm.mysql.Driver</driver-class>
                         <user-name>portal</user-name>
                         <password>portalpassword</password>
                      </local-tx-datasource>
                   </datasources>
                
                   
  2. Now, you will need to create a second datasource for the destination database. In our example we will create, portal-migration-ds.xml file that looks like this:

                      
                   <?xml version="1.0" encoding="UTF-8"?>
                   <datasources>
                      <local-tx-datasource>
                         <jndi-name>PortalDS_2_4</jndi-name>
                         <connection-url>jdbc:mysql://localhost:3306/jbossportal24?useServerPrepStmts=false</connection-url>
                         <driver-class>org.gjt.mm.mysql.Driver</driver-class>
                         <user-name>portal</user-name>
                         <password>portalpassword</password>
                      </local-tx-datasource>
                   </datasources>
                
                   

4.1.3. Obtaining the Migration Application

The JBoss Portal Migration Application can be obtained either as a ready to deploy web application or in source form.

4.1.3.1. Downloading binary

You can find a prepared binary at:

  • Download section of JBoss Portal project page

4.1.3.2. Building from source

You can obtain portal sources from either:

  • Download section of JBoss Portal project page

  • CVS by running following command:

                         
                            cvs -d :pserver:anonymous@anoncvs.forge.jboss.com:/cvsroot/jboss co jboss-portal-2.4
                         
                      

Using the second method you will always have all latest updates from portal 2.4 cvs branch

After downloading the sources you need to build the Migration Application. Before you start be sure you have JBOSS_HOME environment variable set pointing to JBoss Application Server directory. Migration Application archive can be build using following commands:

               
                  cd jboss-portal-2.4
                  cd build
                  ./build.sh
                  cd ..
                  cd migration
                  ./build.sh
               
            

Deployable web application archive can be found at jboss-portal-2.4/migration/output/lib/portal-migration.war

You can also deploy it automatically by executing:

               
                  cd jboss-portal-2.4
                  cd migration
                  ./build.sh deploy
               
            

4.1.4. Deploying the Migration Application

The steps below will guide you through deploying and running the migration application:

  1. Shut down JBoss Application Server

  2. Undeploy/Remove JBoss Portal 2.2 (JBOSS_HOME/server/default/deploy/jboss-portal.sar)

  3. Delete JBOSS_HOME/server/default/data/portal/cms (This directory will be created for you, once again, when JBoss Portal 2.4 initializes.

  4. Deploy the two necessary datasource descriptors, from Section 4.1.2, “DataSource Requirements/Preparation” to JBOSS_HOME/server/default/deploy/*

  5. Deploy the Migration Application, you obtained from Section 4.1.3, “Obtaining the Migration Application” to JBOSS_HOME/server/default/deploy/portal-migration.war

  6. Start JBoss Application Server

4.1.5. Running the Migration Application

  1. After deploying Migration Application you can access it at http://localhost:8080/portal-migration . It is password protected so you need to specify:

    • User: admin

    • Password: simplePassword

    Note

    The Password can be changed in portal-migration.war/WEB-INF/classes/users.properties file. Remember to always change the password to a less trivial one, or undeploy the war file after the migration process.

  2. If you logged in successfully you should access this page:

  3. At Step 2: 2.4 Database Connectivity Check you need to provide datasouce name that points to JBoss Portal 2.4 database (the destination one)

  4. Step 3: Create Tables

  5. If both connections were valid and database schema was created successfully you can follow with the migration process. It is separated into following parts:

    • CMS Data Migration - migrates portal CMS tables content

    • User/Role Data Migrate - migrates portal user, roles and relations beetween them

    • Portal Object Data Migrate - migrates whole portal objects structure. This means nodes like portals, pages and windows.

    • Portal Portlet Instance Data Migrate - migrates all portlet instances presented in portal. For each portlet instance its preferences are also persisted. Next, all already migrated users are iterated and user preferences related to portlet instance are migrated

    • Portal Security Data Migrate - migrates security data for portal objects and portlet instances.

    Which should lead to a successfull end :)

Note

If any error occured during the migration process you will be provided with specific information and asked to retry that step
Always check the Application Server console output or logs after migration to track possible errors.

4.1.6. Final steps

After running the Migration Application you need to perform some additional steps to finish the process:

  1. Shutdown JBoss Application Server

  2. Undeploy JBoss Portal 2.2 (jboss-portal.sar)

  3. Undeploy the JBoss Portal 2.2 datasource descriptor

  4. Delete JBOSS_HOME/server/default/data/portal/cms (This directory will be created for you, once again, when JBoss Portal 2.4 initializes.

  5. Edit your 2.4 datasource file and modify the jndi name: <jndi-name>PortalDS</jndi-name>

  6. Deploy JBoss Portal 2.4.

  7. Start JBoss Application Server

4.2. Migrating Portlet Descriptors

Since 2.2 version of JBoss Portal data from portlet descriptor files are persisted in database. There is special <if-exists/> tag that describes what should portal do when he process descriptor and found data for such portlet application already in database. Therefore after database migration portal will use persisted data.

There are some differences beetween 2.2 and 2.4 descriptors. portlet-instances.xml file was reintroduced because of WSRP implementation caused portal architecture changes. Altough to avoid confusion legacy descriptors support was implemented in 2.4 so all 2.2 compiliant portlets should work out of box.

Even if your 2.2 portlets deployed successfully in 2.4 you should update their descriptors. Legacy descriptors support will expire in 2.6 and you will need to use new format to achive more complex targets.

4.2.1. Car Demo Portlet example

Let's show descriptor changes using Car Demo portlet example which is a presentation of JSF portlet. It can be obtained at PortletSwap . In 2.2 prepared version it has such descriptor:

  • cardemo-object.xml

                      
                      <?xml version="1.0" encoding="UTF-8"?>
                      <deployments>
                         <deployment>
                            <if-exists>overwrite</if-exists>
                            <parent-ref>default</parent-ref>
                            <page>
                               <page-name>samples</page-name>
                               <window>
                                  <window-name>CarDemoWindow</window-name>
                                  <instance-ref>CarDemoPortletInstance</instance-ref>
                                  <region>center</region>
                                  <height>0</height>
                               </window>
                            </page>
                         </deployment>
                         <deployment>
                            <if-exists>overwrite</if-exists>
                            <instance>
                               <instance-name>CarDemoPortletInstance</instance-name>
                               <component-ref>cardemo.CarDemoPortlet</component-ref>
                            </instance>
                         </deployment>
                      </deployments>
                      
                   

Note that as we said before you can successfully deploy it on JBoss Portal 2.4. But because such descriptor format is 2.2 specific you will end with a warning on JBoss Application Server console output:

            
            INFO  [PortletAppDeployment] These instances have been found in -object.xml, you should put them in the file
            c:\jboss-4.0.4.GA\server\default\.\deploy\cardemo.war\WEB-INF/portlet-instances.xml
            INFO  [PortletAppDeployment] <?xml version="1.0" encoding="utf-8" standalone="yes"?>
            <deployments>
               <deployment>
                  <instance>
                     <instance-id>CarDemoPortletInstance</instance-id>
                     <portlet-ref>CarDemoPortlet</portlet-ref>
                  </instance>
               </deployment>
            </deployments>
            
         

So all you need to do is to follow suggestion you got in the warning message :)

4.2.2. Updating Car Demo Portlet descriptors

To have descriptors in our example portlet 2.4 valid you need to follow few simple steps:

  • In cardemo-object.xml file comment out whole <deployment>...</deployment> tag which contains <instance>...</instance> .

  • Copy the text you just commented out and put it in newly created portlet-instances.xml file.

  • Edit and change portlet-instances.xml file using following rules:

    Surround whole file content with </deployments> tag.

    Replace </instance-name> tag with </instance-id> one

    Replace </component-ref> tag with </portlet-ref> one

So after updates your portlet descriptors should look like this:

  • cardemo-object.xml

                      
                      <?xml version="1.0" encoding="UTF-8"?>
                      <deployments>
                         <deployment>
                            <if-exists>overwrite</if-exists>
                            <parent-ref>default</parent-ref>
                            <page>
                               <page-name>samples</page-name>
                               <window>
                                  <window-name>CarDemoWindow</window-name>
                                  <instance-ref>CarDemoPortletInstance</instance-ref>
                                  <region>center</region>
                                  <height>0</height>
                               </window>
                            </page>
                         </deployment>
                      </deployments>
                      
                   
  • portlet-instances.xml

                      
                      <?xml version="1.0" encoding="utf-8" standalone="yes"?>
                      <deployments>
                         <deployment>
                            <instance>
                               <instance-id>CarDemoPortletInstance</instance-id>
                               <portlet-ref>CarDemoPortlet</portlet-ref>
                            </instance>
                         </deployment>
                      </deployments>
                      
                   

Chapter 5. Portlet Primer

Roy Russo

5.1. JSR 168 Overview

The JSR 168 specification aims at defining porlets that can be used by any JSR168 portlet container also called portals. There are different portals out there with commercial and non-commercial licences. In this chapter we will briefly describe such portlets but for more details you should read the specifications available on the web.

Note

This section is a brief overview of the JSR 168 Portlet Specification , and it does not cover the topics in great detail. We strongly encourage portlet developers to read the Specification that can be found here .

As of today, JBoss portal is fully JSR168 1.0 compliant, that means that any JSR168 portlet will behave as it should inside the portal.

5.1.1. Portal Pages

A portal can be seen as pages with different areas and inside areas, different windows and each window having one portlet.

5.1.2. Rendering Modes

A porlet can have different view modes, three modes are defined by the specification but a portal can extend those modes. The 3 modes are:

  • VIEW - Generates markup reflecting the current state of the portlet.
  • EDIT - Should allow a user to customize the behaviour of the portlet.
  • HELP - Should provide some information to the user as to how to use the portlet.

5.1.3. Window States

Window states are an indicator of how much page real-estate a portlet should consume on any given page. There are 3 states defined by the specification:

  • NORMAL - A portlet shares this page with other portlets.
  • MINIMIZED - A portlet may show very little information or none at all.
  • MAXIMIZED - A portlet may be the only portlet displayed on this page.

5.1.4. Section Status

This overview of the portlet specification, is a work in progress. Check back for more in-depth analsis of the specification, but please read on for real-world cases of how to leverage the specification.

5.2. Tutorials

The tutorials contained in this chapter are targetted toward portlet developers. Although they are a good starting and reference point, we do heavily recommend that portlet developers read and understand the Portlet Specification (JSR-168) . We also recommend, using our JBoss Portal User Forums for user-to-user help, when needed.

5.2.1. Deploying your first portlet

5.2.1.1. Introduction

This section will introduce the reader to deploying his first portlet in JBoss Portal. It requires you download the HelloWorldPortlet from PortletSwap.com, using this link .

5.2.1.2. Package Structure

Portlets are packaged in war files, just like other JEE applications. A typical portlet war file can also include servlets, resource bundles, images, html, jsps, and other static or dynamic files you would commonly include.

5.2.1.3. The Portlet Class

Included in the download bundle you should have one java source file: HelloWorldPortlet\src\main\org\jboss\portlet\hello\HelloWorldPortlet.java , and it should contain the following:

                  package org.jboss.portlet.hello;

import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.UnavailableException;
import java.io.IOException;
import java.io.PrintWriter;

public class HelloWorldPortlet extends GenericPortlet
{
   protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
   {
      rResponse.setContentType("text/html");
      PrintWriter writer = rResponse.getWriter();
      writer.write("Hello World!");
      writer.close();
   }
}
               

Now lets dissect our simplest of portlets:

  • public class HelloWorldPortlet extends GenericPortlet

    All Portlets MUST implement the javax.portlet.GenericPortlet Interface.

  • protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws
                               PortletException, IOException, UnavailableException

    In this case, our doView will be called when the portlet is asked to render output in VIEW Mode.

  • rResponse.setContentType("text/html");

    Just like in the servlet-world, you must declare what content-type the portlet will be responding in.

  • PrintWriter writer = rResponse.getWriter();
    writer.write("Hello World!");
    writer.close();

    Here we output the text Hello World! in our portlet window.

    Note

    Portlets are responsible for generating markup fragments, as they are included on a page and surrounded by other portlets.

5.2.1.4. The Application Descriptors

JBoss Portal requires certain descriptors be included in your portlet war, for different reasons. Some of these descriptors are defined by the Portlet Specification, and some are specific to JBoss Portal.

Now lets explain what each of these does:

  • portlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
                 version="1.0">
       <portlet>
          <portlet-name>HelloWorldPortlet</portlet-name>
          <portlet-class>org.jboss.portlet.hello.HelloWorldPortlet</portlet-class>
          <supports>
             <mime-type>text/html</mime-type>
             <portlet-mode>VIEW</portlet-mode>
          </supports>
          <portlet-info>
             <title>HelloWorld Portlet</title>
          </portlet-info>
       </portlet>
    </portlet-app>

    This file must adhere to its definition in the Portlet Specification. You may define more than one portlet application in this file.

    • <portlet-name>HelloWorldPortlet</portlet-name>

      Define your portlet name. It does not have to be the Class name.

    • <portlet-class>org.jboss.portlet.hello.HelloWorldPortlet</portlet-class>

      The FQN of your portlet class must be declared here.

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

      The supports attributes allow you to declare extra vital information about the portlet. In this case, we are letting the portal know that it will be outputting text/html and only support a VIEW mode.

      Note

      A content-type must be declared here for every portlet, and it must match with how the portlet is programmatically responding. Likewise, a portlet mode must be declared here and have a corresponding method in its class. In our case, the VIEW mode will map to the doView() in our class.

    • <portlet-info>
         <title>HelloWorld Portlet</title>
      </portlet-info>
      

      The portlet's title will be displayed as the header in the portlet window, when rendered, unless it is overridden programatically.

  • portlet-instances.xml

    <deployments>
       <deployment>
          <instance>
             <instance-id>HelloWorldPortletInstance</instance-id>
             <portlet-ref>HelloWorldPortlet</portlet-ref>
          </instance>
       </deployment>
    </deployments>

    This is a JBoss Portal specific descriptor that allows you create an instance of a portlet. The portlet-ref value must match the portlet-name value given in the packaged portlet.xml . The instance-id value can be named anything, but it must match the instance-ref value given in the *-object.xml file we will explore below.

  • helloworld-object.xml

    <deployments>
       <deployment>
          <if-exists>overwrite</if-exists>
          <parent-ref>default.default</parent-ref>
          <window>
             <window-name>HelloWorldPortletWindow</window-name>
             <instance-ref>HelloWorldPortletInstance</instance-ref>
             <region>center</region>
             <height>1</height>
          </window>
       </deployment>
    </deployments>

    The *-object.xml is responsible for creating/configuring windows, pages, and even portal instances. In our example, we are creating a portlet window, assigning it to a page, and specifying where it should appear on that page. This is a specific descriptor to JBoss Portal.

    • <if-exists>overwrite</if-exists>

      Instructs the portal to overwrite or keep this object if it already exists. Possible values are overwrite or keep . Overwrite will destroy the existing object and create a new one based on the content of the deployment. Keep will maintain the existing objct deployment or create a new one if it does not yet exist.

    • <parent-ref>default.default</parent-ref>

      Tells the portal where this portlet should appear. In this case, default.default specifies that this portlet should appear in the portal instance named default and the page named default .

    •                                     <window-name>HelloWorldPortletWindow</window-name>

      Can be named anything.

    •                                     <instance-ref>HelloWorldPortletInstance</instance-ref>

      The value of instance-ref must match the value of instance-id found in the portlet-instances.xml .

    • <region>center</region>
      <height>1</height>

      Specify the layout region and order this window will be found on the portal page.

To illustrate the relationship between the descriptors , we have provided this simple diagram

5.2.1.5. Building your portlet

If you have downloaded the sample, you can execute the build.xml with ANT or inside your IDE. Executing the deploy target will compile all src files and produce a helloworldportlet.war under HelloWorldPortlet\helloworldportlet.war.

If you want to create an expanded war directory, after executing the above deploy target, you should execute the explode target.

The above target will produce the following:

This will deflate the helloworldportlet.war, and allow you to deploy it as an expanded directory. It will work just the same, with some additional benefits noted below:

The advantage to expanded war deployments is that you can modify xml descriptors, resource files jsp/jsf pages easily during development. Simply touch the web.xml to have JBoss Application Server hot-deploy the web appllication on a live-running server instance

5.2.1.6. Deploying your portlet

Deploying a portlet is as simple as copying/moving the helloworldportlet.war in to the server deploy directory. Doing this on a running instance of the portal and application server, will trigger a hot-deploy :

18:25:56,366 INFO  [Server] JBoss (MX MicroKernel) [4.0.3SP1 (build: CVSTag=JBoss_4_0_3_SP1 date=200510231054)] Started in 1m:3s:688ms
18:26:21,147 INFO  [TomcatDeployer] deploy, ctxPath=/helloworldportlet, warUrl=.../tmp/deploy/tmp35219helloworldportlet-exp.war/
               

Pointing your browser to http://localhost:8080/portal/ , should yield a view of our HelloWorldPortlet:

5.2.2. A Simple JSP Portlet

5.2.2.1. Introduction

This section will introduce the reader to deploying a simple JSP portlet in JBoss Portal. It requires you download the HelloWorldJSPPortlet from PortletSwap.com, using this link .

This portlet will introduce you to using JSPs for view rendering and the portlet taglib for generating links.

5.2.2.2. Package Structure

Portlets are packaged in war files, just like other JEE applications. A typical portlet war file can also include servlets, resource bundles, images, html, jsps, and other static or dynamic files you would commonly include.

5.2.2.3. The Portlet Class

Included in the download bundle you should have one java source file: HelloWorldPortlet\src\main\org\jboss\portlet\hello\HelloWorldJSPPortlet.java , and it should contain the following:

                  
package org.jboss.portlet.hello;

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 javax.portlet.UnavailableException;
import java.io.IOException;

public class HelloWorldJSPPortlet extends GenericPortlet
{
   protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
   {
      rResponse.setContentType("text/html");

      String sYourName = (String) rRequest.getParameter("yourname");

      if(sYourName != null)
      {
         rRequest.setAttribute("yourname", sYourName);
         PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/view2.jsp");
         prd.include(rRequest, rResponse);
      }
      else
      {
         PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/view.jsp");
         prd.include(rRequest, rResponse);
      }
   }

   public void processAction(ActionRequest aRequest, ActionResponse aResponse) throws PortletException, IOException, UnavailableException
   {
      String sYourname = (String) aRequest.getParameter("yourname");

      // do something

      aResponse.setRenderParameter("yourname", sYourname);
   }

   protected void doHelp(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
   {
      rResponse.setContentType("text/html");
      PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/help.jsp");
      prd.include(rRequest, rResponse);
   }

   protected void doEdit(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
   {
      rResponse.setContentType("text/html");
      PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/edit.jsp");
      prd.include(rRequest, rResponse);
   }
}
               

Now lets look at some of our methods:

  •                            
                               protected void doHelp
    
                               AND
    
                               protected void doEdit
                            

    Support for these Modes must be declared in the portlet.xml. They will be triggered when a user clicks on the respective icons in the portlet window titlebar, or through generated links within the portlet.

  • public void processAction(ActionRequest aRequest, ActionResponse aResponse) throws PortletException, IOException, UnavailableException
    {
       String sYourname = (String) aRequest.getParameter("yourname");
    
       // do something
    
       aResponse.setRenderParameter("yourname", sYourname);
    }
                            

    This method will be triggered upon clicking on an ActionURL from our view.jsp. It will retrieve yourname from the HTML form, and pass it along as a renderParameter to the doView().

  • rResponse.setContentType("text/html");

    Just like in the servlet-world, you must declare what content-type the portlet will be responding in.

  • protected void doView(RenderRequest rRequest, RenderResponse rResponse) throws PortletException, IOException, UnavailableException
    

    In this case, our doView, is responsible for dispatching to the appropriate jsp view.jsp or view2.jsp , depending on the existence of the yourname parameter passed in from the processAction .

5.2.2.4. The Application Descriptors

JBoss Portal requires certain descriptors be included in your portlet war, for different reasons. Some of these descriptors are defined by the Portlet Specification, and some are specific to JBoss Portal. For brevity, we only discuss the portlet.xml descriptor here. For discussion on the other descriptors, please view Section 5.2.1.4, “The Application Descriptors” or the chapter on descriptors: Section 6.1, “Portlet Descriptors” .

  • portlet.xml

    <?xml version="1.0" encoding="