Archive

Posts Tagged ‘navigation’

Navigation in Seam/JSF

April 8, 2009 Leave a comment

 <navigation>

Seam also allows you to specify navigation rules in pages.xml. This can be more convenient than specifying navigation in the typical JSF way.

Take the following JSF navigation rule, for example:

    <navigation-rule>
        <from-view-id>/pagewithlink.xhtml</from-view-id>  (1)
        <navigation-case>
            <from-outcome>first</from-outcome>            (2)
            <to-view-id>/first.xhtml</to-view-id>         (3)
            <redirect/>                                   (4)
        </navigation-case>
    </navigation-rule>
  1. The view id of the page that produces the outcome.
  2. The outcome id.
  3. The destination view.
  4. Optional redirect tag for redirect after post

Using Seam, this can be represented in pages.xml as:

  <page view-id="/pagewithlink.xhtml">       (1)
    <navigation>
      <rule if-outcome="first">              (2)
        <redirect view-id="/first.xhtml"/>   (3)
      </rule>
    </navigation>
  </page>
  1. The view id of the page that produces the outcome.
  2. The outcome id is specified using <rule if-outcome="...">.
  3. The destination is a redirect element in this case.

Not only is this more compact than the JSF way, it is also possible to eliminate the outcome strings from the application and replace them with EL expressions using <rule if="... EL expr"> syntax:

  <page view-id="/pagewithlink.xhtml">       (1)
    <navigation>
      <rule if="#{theSfsb.goodToGo}">        (2)
        <redirect view-id="/first.xhtml"/>   (3)
      </rule>
    </navigation>
  </page>
  1. The view id of the page that produces the outcome.
  2. Instead of specifying an outcome string, we use an EL expression to invoke a method on a SFSB which will return a boolean.
  3. The destination is the same  redirect element

No more nasty outcome strings in the EJB!

Advertisements
Categories: Jboss Seam Tags: ,