The JSF Module

this module makes the integration of spring-annotation and JSF really easy.

* It registers automatically a VariableResolver in the JSF stack to enable the use of the spring beans as managed beans

* it adds 2 (two) more scopes to spring framework: flash and conversation

* it registers a navigation handler in the JSF stack to enable you to write less code

* it adds some annotations to make it easier to write JSF code

Scopes

the flash scope is almost the same as the flash scope from RoR, beans living in the flash scope exists from the end of a request to the begining of the next request.

the conversation scope is a scope that exists from the opint where an action annotated with @ConvStart is run, to the moment after an action annotated with @ConvEnd is runned.

Convencion over Configuration in JSF is possible

To enable the use of Convencion over configuration, at least in the navigation rules of a JSF application, we have created a custom navigation handler.

You can still use the navigation rules in your faces-config.xml, but if an action returns a string that starts with "def:" this navigation handler intercepts the default flow and starts the CoC approach.

it works in the following way:



from a JSF page you click in a button that has the action proparty set to "#\{myBean.myAction\}"

in the class MyBean in the method myAction the only code you have is: return "def:aPage"

the navigation handler will render the page: /myBean/aPage.jsf

or /"the name of the bean"/"the name returned after def:"

Annotations

You can use the JSF module annotations only in a bean annotated with @ManagedBean it is a marker annotation telling this module that a bean is a ManagedBean



* @DataModel, @DataModelIndex and @DataModelSelection

This annotations convert a java.util.List to a ListDataModel to be used in a JSF DataTable tag value

after this when you click on a link or button in the table the property annotated with @DataModelIndex will receive the index of the line, and the property annotated with @DataModelSelection will receive the value bean user to fill that row



* @Out

this annotation exports a property of a bean in the chosen scope, the default scope is flash



* @ConvStart and @ConvEnd

this annotations marks the start and end of a conversation scope



* @Value

this annotation os similar to the @Property annotation, but it uses JSF EL to get its value, this way you can fill a property with a value like: $\{aBean.aproperty.anoterProperty\}



* @IfInvalid

this annotation marks an action method that needs to be validated using the hibernate-validatos module

Examples

Examples



the Example 3, or Example 3 - with libs project shows how to use this module

Usage

Usage



to use this module you need to configure your web.xml adding as follows:

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath*:applicationContext.xml</param-value>

</context-param>

<context-param>

<param-name>contextClass</param-name>

<param-value>net.sourceforge.sannotations.web.TOAnnotationXmlWebApplicationContext</param-value>

</context-param>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

<filter>

<filter-name>requestContext</filter-name>

<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>requestContext</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<servlet>

<servlet-name>Faces Servlet</servlet-name>

<servlet-class>org.apache.myfaces.webapp.MyFacesServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>Faces Servlet</servlet-name>

<url-pattern>*.jsf</url-pattern>

</servlet-mapping>

in this version there is no need to enable the AspectJ loadtime weaving anymore.



All done!