Apache MyFaces 1.2 Web Application Development — Save 50%
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:
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:
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:
- 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
- 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
|Building next-generation web applications with JSF and Facelets|
eBook Price: $26.99
Book Price: $44.99
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:
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:
- Choose the Server view, and then click on New | Server, as shown in the following screenshot:
- Select JBoss v.4.2 (Seam is specified to work with 4.2), as shown in the following screenshot:
- 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 22.214.171.124 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 :
- Apache MyFaces Trinidad 1.2 Web Application Groundwork: Part 1
- Most Wanted Apache MyFaces Trinidad 1.2 Tags and Tag Attributes
|Develop JSF web applications with Trinidad and Seam|
eBook Price: $29.99
Book Price: $49.99
About the Author :
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.
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.