Monday, March 16, 2009

Basic RichFaces Project with Spring

To create basic RichFaces enabled project, you can run the following maven command provided by JBoss.
mvn archetype:generate
-DarchetypeGroupId=org.jboss.portletbridge.archetypes
-DarchetypeArtifactId=richfaces-basic
-DarchetypeVersion=1.0.0.B6
-DgroupId=org.whatever.project
-DartifactId=myprojectname
-DarchetypeRepository=http://repository.jboss.org/maven2/
Make sure that you use the proper version of the Portlet Bridge of Jboss. Read more here
To enable Spring to manage your JSF Beans you should add this context arguments to your web.xml




org.springframework.web.context.ContextLoaderListener





org.springframework.web.context.request.RequestContextListener




This are the listeners which enables Spring to load it's context and create the beans, and to process Request from JSF to Spring and preserve the session.

Inside of faces-config.xml :



org.springframework.web.jsf.DelegatingVariableResolver




This delegates the JSF Variable resolver to look up for EL Expressions defined beans in Spring. In other words, it replaces the standard JSF EL resolver.

Now you would be able to define your JSF Beans in Spring as follows:



xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">







This bean can be used with your JSF Tag as usual:





In deed simple.

Here is the full web.xml:



xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


javax.faces.STATE_SAVING_METHOD
server




javax.portlet.faces.renderPolicy
ALWAYS_DELEGATE



org.ajax4jsf.RESOURCE_URI_PREFIX
rfRes



org.richfaces.LoadStyleStrategy
NONE



org.richfaces.LoadScriptStrategy
NONE



org.ajax4jsf.COMPRESS_SCRIPT
true



org.richfaces.CONTROL_SKINNING
enable



contextConfigLocation
classpath:spring-context.xml



RichFaces Filter
richfaces
org.ajax4jsf.Filter



richfaces
Faces Servlet
REQUEST
FORWARD
INCLUDE



com.sun.faces.config.ConfigureListener



org.springframework.web.context.ContextLoaderListener



org.springframework.web.context.request.RequestContextListener





Faces Servlet
javax.faces.webapp.FacesServlet
1




Faces Servlet
/faces/*


Faces Servlet
*.jsf



FacesServlet
*.mk




10



Restrict access to JSP pages

Restrict access to JSP pages



With no roles defined, no access granted



BASIC




No comments:

Post a Comment