Apache MyFaces Trinidad 1.2 Web Application Groundwork: Part 2

Exclusive offer: get 50% off this eBook here
Apache MyFaces 1.2 Web Application Development

Apache MyFaces 1.2 Web Application Development — Save 50%

Building next-generation web applications with JSF and Facelets

$26.99    $13.50
by David Thomas | November 2009 | Web Development

Read Part One of Apache MyFaces Trinidad 1.2 Web Application Groundwork here.

Deployment

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
Apache MyFaces 1.2 Web Application Development Building next-generation web applications with JSF and Facelets
Published: March 2010
eBook Price: $26.99
Book Price: $44.99
See more
Select your format and quantity:

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:
    <copy
    tofile="${war.dir}/WEB-INF/classes/META-INF/services/
    org.apache.myfaces.trinidad.context.PageFlowScopeProvider"
    file="${basedir}/resources/META-INF/services/
    org.apache.myfaces.trinidad.context.PageFlowScopeProvider"
    overwrite="true"
    />
  • 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"/>
    </fileset>
    </copy>

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 2.0.0.17 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:
    <context-param>
    <param-name>
    org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION
    </param-name>
    <param-value>
    true
    </param-value>
    </context-param>

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

Summary

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 :


Apache MyFaces Trinidad 1.2: A Practical Guide Develop JSF web applications with Trinidad and Seam
Published: December 2009
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

About the Author :


David Thomas

David Thomas is a developer and technical project manager of Java-based web applications and has well over 10 years of experience in various web technologies.

He began writing applications based on the Common Gateway Interface (CGI), HTML and Javascript, with a short Java Applets interlude.

The main occupation with Java began when Java took charge of the server. A series of Java Servlet applications were developed using an early, self-built Model-2 controller architecture. Java Server Pages (JSP) took hold for a rather long time and a couple of major, increasingly complex web applications were developed in combination with Struts.

Shortly after Java Server Faces 1.2 (JSF) emerged, began the development of a major JSF web application including the development of a high-level framework based on Apache My Faces Trinidad, Facelets and JBOSS Seam in the area of controlling. This project spawned a couple of sub projects so development continues up to the present day.

This is the author's first book which is highly influenced by the accumulated years of his experience in web technology.

Books From Packt


ICEfaces 1.8: Next Generation Enterprise Web Development
ICEfaces 1.8: Next Generation Enterprise Web Development

jQuery UI 1.7: The User Interface Library for jQuery
jQuery UI 1.7: The User Interface Library for jQuery

Apache Geronimo 2.1: Quick Reference
Apache Geronimo 2.1: Quick Reference

JBoss RichFaces 3.3
JBoss RichFaces 3.3

jQuery 1.3 with PHP
jQuery 1.3 with PHP

Apache CXF Web Service Development
Apache CXF Web Service Development

Grails 1.1 Web Application Development
Grails 1.1 Web Application Development

Tomcat 6 Developer's Guide
Tomcat 6 Developer's Guide


No votes yet

Post new comment

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
c
q
P
8
j
N
Enter the code without spaces and pay attention to upper/lower case.
Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software