Apache MyFaces Trinidad 1.2 Web Application Groundwork: Part 2

Building next-generation web applications with JSF and Facelets


Deployment is very easy because with Seam-gen, we also inherit the deployment mechanism (already run during the project setup, earlier) provided by the Ant build process of Seam-gen. However, a few notes regarding the specific deployment of a Trinidad and Facelet web application in contrast with Seam-gen are discussed in more detail in the upcoming topics. The following screenshot shows the referenced libraries within the Eclipse IDE:

Trinidad-specific and Facelet-related changes to the project files

First of all, the lib directory lacks the Trinidad JAR files and the Facelet JAR:

  • jsf-facelets-1.1.14.jar
  • trinidad-api-1.2.9.jar
  • trinidad-impl-1.2.9.jar

So above JAR files must be added to the lib directory while others, such as the RichFaces JARs, should be removed as we want to achieve a clean setup of a single component library. A mix-up should be avoided to keep away from integration problems. The following screenshot shows the contents of the lib directory inside Eclipse (part I only shows files not referenced by the Eclipse project):

Most importantly, we need to update the file deployed-jars.list, as it is looked at by the build process to provide the application server with the required JAR files. So we reduce this list file to a more minimal Trinidad-specific version:

  • antlr-runtime.jar
  • commons-beanutils.jar
  • commons-digester.jar
  • core.jar
  • drools-compiler.jar
  • drools-core.jar
  • janino.jar
  • jboss-el.jar
  • jboss-seam.jar
  • jboss-seam-*.jar
  • jbpm-jpdl.jar
  • jsf-facelets-1.1.14.jar
  • mvel14.jar
  • trinidad-api-1.2.10.jar
  • trinidad-impl-1.2.10.jar

The following screenshot shows the contents of the lib directory inside Eclipse (part II only shows files not referenced by the Eclipse project):

Next, in the resources directory we must add a provider for Seam's conversation mechanism to support Seam conversations in Trinidad dialogs. Its file name must follow the Trinidad naming convention for this provider type, and it must be located below resources in META-INF/services:

  • File name: org.apache.myfaces.trinidad.PageFlowScopeProvider
  • Contents: It must contain the name and package path of the provider class, for example, trinidad.SeamPageFlowScopeProviderImpl

This class is created as an implementation of Trinidad's abstract class PageFlowScopeProvider that can be easily done with Eclipse's comfortable class creation wizard.

There are further simplifications:

  1. The org.jboss.seam.ui.richfaces package in the resources directory is required for Seam's support of RichFaces, but is obsolete for us and should thus be deleted
  2. In the WEB-INF directory, we can carry out the following activities:
    • We can add a folder for Facelet composition components
    • We can simplify the components.xml file by getting rid of persistence declarations such as persistence:managed-persistence-context, persistence:entity-manager-factory, and drools:rule-base declarations (the security we only leave is the one for the identity object)
    • The faces-config must be adapted to suit the Trinidad renderer as described earlier
    • The pages.xml becomes even simpler as we practically avoid it altogether using the dialog framework as described in the navigation section earlier
    • We must modify the web.xml to suit Trinidad's requirements
    • We must add three additional files, namely the trinidad-config.xml, the trinidad-skins.xml, and a taglib.xml to declare the Facelet composition components
    • The *-dev-ds.xml and *-prod-ds.xml files may be emptied of any specific data because no database-backing is used in our test project

Trinidad-specific changes to the Ant build script

The build.xml in the project root must only be slightly adapted as follows:

  • The war target must be extended to also copy the PageFlowScopeProivder class, that is:
  • Furthermore, this target needs an addition to cover the Facelet components, that is:
    <copy todir="${war.dir}/WEB-INF">
    <fileset dir="${basedir}/resources/WEB-INF">
    <include name="lib/*.*"/>
    <include name="faceletComponents/*.*"/>
    <include name="classes/**/*.class"/>

Deployment from Eclipse

Now, deployment is child's play. After you have configured the application server path in the build.properties file, updated its only property jboss.home to your local JBOSS installation (for example jboss.home =/Applications/JBoss/jboss-4.2.2.GA), and set up Eclipse to use JBOSS as application server, carry out the following steps:

  1. Choose the Server view, and then click on New | Server, as shown in the following screenshot:

  2. Select JBoss v.4.2 (Seam is specified to work with 4.2), as shown in the following screenshot:

  3. Leave the configured projects in the Add and Remove Projects dialog empty, as the project is deployed by the Seam-gen Ant build. Click on Finish.

Any change to any project file causes the Ant build process to be rerun. This also includes a deployment to the JBoss application server in its final step.

Of course, it is always possible to switch off the automated build and deploy, particularly in cases where the applied machine has not enough performance. However, because of the thinness of the sample project, this should not be necessary (even on an IBook G4 the JBoss starts up in a minute).

Browser client setup

As a browser, I recommend Firefox 2 or Firefox 3. The latter version still has a few compatibility issues, but they should soon be resolved. Furthermore, there are a few subtle configuration issues to take care of that are stated as follows:

  • From my past experience, I have seen that Seam and Trinidad work well when Cookies are disabled because when we take a server-side approach, this is not an issue. Remember that both Trinidad and Seam support client-side techniques; however, this is not an area that this article aims to cover.
  • Versions of Firefox below should be avoided because of security and memory management issues. The following screenshot shows how Firefox's Privacy preferences tab allows setting up exceptions for cookies.

  • Disabled cookies make sure that that session and conversation management is properly handled, and that a unique session ID is assigned for each session that the user opens. This is not critical for this web sample application, but would be important to consider for real-life applications. The following screenshot shows the event of clicking on disable to set up disabled cookies for a Seam or Trinidad web application on the your_server host:

  • Last but not least, when it comes to Trinidad skinning, setting the very practical web.xml parameter switch to true only works with disabled cookies which, in terms of effective work, is crucial while the skin is being developed:

The following screenshot shows how to set up disabled cookies for a Seam or Trinidad web application on the your_server host:


In this article, we have seen the basic parts of the web sample application that serves as Trinidad—for example, login registration, user authorization, navigation, internationalization, and polling—have been discussed with occasional refinement where required.

Login and authorization are based on Seam's security framework. It allows using an identity object that keeps the user's credentials that result from her or his login to the application through login page supported by Seam.

In connection with navigation, we took a look at the Trinidad dialog frameworks that are used in the sample application to navigate with a minimum declaration effort for each page because the dialog framework allows a purely programmatic approach of dialog creation, usage, and closure.

Internationalization is implemented by the application of the Seam messages object. It is applied in two ways. First, all Facelet composition components are equipped with JSTL logic that looks up the respective messages properties file according to the provided label and ID of the respective component. Second, the messages object is directly used for any other components that are not encapsulated as composition components.

If you have read this article you may be interested to view :

Books to Consider

Apache MyFaces Trinidad 1.2: A Practical Guide
$ 29.99
Apache MyFaces 1.2 Web Application Development
$ 26.99
web2py Application Development Cookbook
$ 29.99
JSF 1.2 Components
$ 26.99
comments powered by Disqus