On-Load is a custom JSF phase listener that allows JSF actions to be executed when a page is loaded (after a view has been created) and change the current view to a new view based on the existing navigation rules.
You only need a JSF implementation (tested on MyFaces 1.1.1) and the Apache commons logging (log4j backend recommended).
Make sure you have the JSF API and apache-commons on your container classpath
Copy the following Jar files from the latest jsfExt release to your WEB-INF/lib directory (on-load is the only component currently in the JSF Ext. sub-project and does not have an independent jar file):
Copy the configuration files to your /WEB-INF directory:
Tell the phase listener where to find the configuration file
<context-param> <param-name>onload-config</param-name> <param-value>/WEB-INF/onload-config.xml</param-value> </context-param>
Register the phase listener with JSF.
Note: it is important to register this listener below the Seam phase listener when using the JBoss-Seam framework. This may also be the case with the Shale framework, but I have not tested Shale.
<lifecycle> ... Other phase listeners here ... <phase-listener>net.sf.jsfcomp.ext.onload.OnLoadPhaseListener</phase-listener> </lifecycle>
The source tree includes an example onload configuration file in the 'resources' directory. The structure is similar to that of the faces configuration file to keep the learning curve as small as possible.
The file consists of navigation rules. At most one navigation rule is executed per page load. The rule that matches the URL the most exactly is the rule that is processed. The first child node must be 'view-id'. This contains the path to the view (not the URL, so /file.xhtml instead of /file.jsf for example). The 'action' is an EL expression to a method reference. The optional 'success-result' specifies what outcome (in addition to null) defines a successful result.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<onload-config xmlns="urn:onload-config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:onload-config onload-config.xsd">
<navigation-rule>
<view-id>/welcome.jsp</view-id>
<action>#{bean.actionMethod}</action>
</navigation-rule>
<navigation-rule>
<view-id>/path*</view-id>
<action>#{bean.actionMethod}</action>
</navigation-rule>
</onload-config>