Vineet Manohar is CTO / Co-Founder of online Car Search Engine, iSeeCars.com. Vineet is a DZone MVB and is not an employee of DZone and has posted 20 posts at DZone. You can read more from them at their website. View Full User Profile

How to Configure Multiple page.xml Files in Seam 2.2

04.14.2010
| 6758 views |
  • submit to reddit

Seam lets you specify navigation rules in the pages.xml file which can become very large for apps with many pages and transitions. Seam allows you to break this file into multiple small files. This allows you to easily manage large applications by creating multiple pages.xml files, typically one per page. This article describes how to create multiple pages.xml files in Seam 2.2.

Step 1: Configure /WEB-INF/components.xml

Make sure you declare the navigation namespace at the top of components.xml and each file under <navigation:pages> as follows

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
xmlns:core="http://jboss.com/products/seam/core" xmlns:persistence="http://jboss.com/products/seam/persistence"
xmlns:drools="http://jboss.com/products/seam/drools" xmlns:bpm="http://jboss.com/products/seam/bpm"
xmlns:security="http://jboss.com/products/seam/security" xmlns:mail="http://jboss.com/products/seam/mail"
xmlns:web="http://jboss.com/products/seam/web" xmlns:navigation="http://jboss.com/products/seam/navigation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.2.xsd
http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.2.xsd
http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.2.xsd
http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd
http://jboss.com/products/seam/navigation http://jboss.com/products/seam/navigation-2.2.xsd
http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd">

<mail:mail-session host="localhost" tls="false" ssl="false" port="25" />

<component>
<property name="createTempFiles">true</property>
<property name="maxRequestSize">1000000000</property>
</component>

<component name="org.jboss.seam.core.init">
<!-- enabling this slows down Seam significantly -->
<property name="debug">false</property>
</component>

<core:init transaction-management-enabled="false" />

<security:identity authenticate-method="#{loginController.authenticate}"
remember-me="true" />

<event type="org.jboss.seam.security.notLoggedIn">
<action execute="#{redirect.captureCurrentView}" />
</event>

<event type="org.jboss.seam.security.postAuthenticate">
<action execute="#{redirect.returnToCapturedView}" />
</event>

<navigation:pages>
<navigation:resources>
<!-- global -->
<value>/WEB-INF/pages.xml</value>

<!-- one per page -->
<value>/WEB-INF/createAccount.page.xml</value>
<value>/WEB-INF/login.page.xml</value>
</navigation:resources>
</navigation:pages>
</components>

Step 2. Save all .page.xml files in WEB-INF directory

WEB-INF/createAccount.page.xml  
WEB-INF/login.page.xml

Step 3. Create the .page.xml files.

See the sample file: createAccount.page.xml below. Note that the root tag is <pages>. Make sure that the same page is not repeated in another file.

<?xml version="1.0" encoding="UTF-8"?>
<pages xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">

<page view-id="/createAccount.xhtml" login-required="false">
<!-- Create account -->
<navigation
from-action="#{createAccountController.createAccountFormCreateAccount}">

<!-- Account created -->
<rule if-outcome="accountCreated">
<redirect view-id="/login.xhtml">
<message>Your account has been created. Please log in.</message>
</redirect>
</rule>
</navigation>
</page>
</pages>

FAQ

Can I use Seam 2.0 style <view id>.page.xml files?

You should be able to use viewid.page.xml xml files according to the examples that ship with Seam 2.2.0. However, some users have complained that it doesn’t work in Seam 2.1. I could not get it to work with Seam 2.2.0 as well.

From http://www.vineetmanohar.com/2010/04/13/how-to-configure-multiple-page-xml-files-in-seam-2-2

Published at DZone with permission of Vineet Manohar, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: