org.hibernate.LazyInitializationException when migrating webapp to JSF 2.1 & RichFaces 4 - spring

I know this question has been asked a lot, but the strange thing here is that I had no problems when using jsf 1.1 / richfaces 3, along with hibernate 3.7 and spring 2.5.
Now that I migrated my front-end to jsf 2.1 / richfaces 4 (hibernate and spring remained the same) the following exception appears when I try to access a collection marked as "lazy=true" in hibernate mapping config:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.mu.afs.Afi.cods, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:97)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:225)
at javax.faces.model.ListDataModel.isRowAvailable(ListDataModel.java:91)
at javax.faces.model.ListDataModel.setRowIndex(ListDataModel.java:105)
The collection that I try to reach is referenced by a rich:datatable in the same xhtml that the Afi entity;
Here is the part of the xhtml that tries to access the collecion upon an ajax request of a master table:
<rich:extendedDataTable id="tableCods" selectionMode="single"
selection="#{afiBean.codSelected}"
style="width: 100%; height: 100px"
value="#{afiBean.selectedAfi.cods}" var="cod">
...
<rich:column width="50px" style="text-align: right;">
<f:facet name="header"><h:outputText value="Months"/></f:facet>
<h:outputText value="#{cod.months}" />
</rich:column>
<rich:column width="80px" style="text-align: right;">
<f:facet name="header"><h:outputText value="Cap" /> </f:facet>
<h:outputText value="#{cod.cap}">
<f:convertNumber pattern="######,##0.00" locale="es_AR" />
</h:outputText>
</rich:column>
<rich:column width="200px" style="text-align: center;">
<f:facet name="header"><h:outputText value="Class"/></f:facet>
<h:outputText value="#{cod.clazz}" />
</rich:column>
...
Here is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
...
<filter>
<filter-name>sessionFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
...
This is part of my application-context.xml:
...
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager" />
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="store*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED</prop>
<prop key="read*">PROPAGATION_REQUIRED</prop>
<prop key="load*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
...
The service that is accessing the Afi entity is defined as follow:
<bean id="afiService" parent="txProxyTemplate">
<property name="proxyInterfaces" value="com.mu.afs.services.AfiService" />
<property name="target">
<bean class="com.mu.afs.services.impl.AfiServiceImpl">
<property name="afiDao" ref="afiDao" />
</bean>
</property>
</bean>
<bean id="afiliadosDao"
class="com.mu.afs.dao.impl.HibernateAfiDaoImpl"
parent="hibernateDaoSupport">
</bean>
I would really appreciate if someone can throw some light on this issue. I dont know whether is related to a migration issue or if there is a problem with this configuration and was somehow "masked" with a previous version of jsf and richfaces.
I tried to put here any relevant information that I thought it would help without boring and overwhelm the reader, but let me know if something is missing here.
Thanks in advance.

Related

404 Error on /spring_security_login Spring Security 3.2 after migrating from Tomcat 6 to Tomcat 7

It's been now three days that I'm battling to make my application work again.
The pitch : I had an application using Spring Security 3.2 and running well on Tomcat 6.
I want to migrate all my apps on Tomcat 7, so that's why I'm trying that.
BUT : every time I access to the root of my app, I get a 404 error page, with /spring_security_login written in the URL.
For the /spring_security_login written, it seems partially legit, because Spring is set to create the login form on its own. But why the 404 error ?
On Tomcat 6, with the same web.xml and applicationContext-security, the site is running well.
Last but not least, my login is made through the Spring Security ldap provider, so it adds one more level of complexity...
Here is my web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>MYAPP</display-name>
<!-- où se trouve la conf spring: -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-security.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.security.web.session.HttpSessionEventPublisher
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<!-- Reads request input using UTF-8 encoding -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- configuration spring -->
<servlet>
<servlet-name>myapp-webapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myapp-webapp</servlet-name>
<url-pattern>*.do</url-pattern>
<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myapp_database</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
And my applicationContext-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd">
<s:global-method-security secured-annotations="disabled">
</s:global-method-security>
<s:http pattern="/styles/**" security="none"/>
<s:http pattern="/js/**" security="none"/>
<s:http pattern="/img/**" security="none"/>
<s:http pattern="/html/**" security="none"/>
<s:http pattern="/remoting/**" security="none"/>
<!-- config ldap activee use-expressions="true" -->
<s:http auto-config="true" create-session="always" access-decision-manager-ref="accessDecisionManager">
<s:intercept-url pattern="/cancelPreviousAction.do" access="P_MYAPP_RW" />
<s:intercept-url pattern="/**" access="P_MYAPP_RO" />
<s:session-management>
<s:concurrency-control max-sessions="1" />
</s:session-management>
<s:form-login />
<s:logout/>
</s:http>
<s:authentication-manager>
<s:authentication-provider ref="ldapProvider"></s:authentication-provider>
</s:authentication-manager>
<bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="..." />
<property name="userDn" value="..." />
<property name="password" value="..." />
</bean>
<bean id="ldapProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
<constructor-arg>
<bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
<constructor-arg ref="contextSource" />
<property name="userSearch">
<bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg index="0" value="..." />
<constructor-arg index="1" value="..." />
<constructor-arg index="2" ref="..." />
</bean>
</property>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<constructor-arg ref="contextSource" />
<constructor-arg value="..." />
<property name="rolePrefix" value="" />
<property name="searchSubtree" value="true" />
<property name="convertToUpperCase" value="false" />
</bean>
</constructor-arg>
</bean>
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
<property name="allowIfAllAbstainDecisions" value="false" />
<property name="decisionVoters">
<bean class="org.springframework.security.access.vote.RoleVoter">
<property name="rolePrefix" value=""/>
</bean>
</property>
</bean>
</beans>
Anybody has a clue ?
I though one time that it might be my Tomcat conf that would be the cause, but now when I call the root url of my app, the /spring_security_login appends itself in the url, so I think the redirection inside Spring Seuciryt works well...
NB : When I remove the spring Security filter from the web.xml file, the app works well (except the login/security part needless to say).
Thanks in advance !
In fact the problem was that under Tomcat 6, I had overrided the definition of the default servlet.
After having searched long times and long times, I tried commenting the default servlet definition... and everything worked.
So in web.xml, comment the following lines to have the same :
<!--
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
<url-pattern>*.gif</url-pattern>
</servlet-mapping> -->
And it fixed everything.

Spring MVC POST not supportet

i wan't to configure spring mvc via UrlBasedViewResolver in an existing webflow, JSF- Primefaces project cause i need clean URLs. Unfortunately my SearchForm get an
WARN PageNotFound:183 - Request method 'POST' not supported
warn if it fires ajax or action.
In case of form action the associated method in my #ManagedBean dont get called.
Now, I ask you to help...
web.xml
<display-name>My Transport</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:res/conf/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFSULT_SUFFIX</param-name>
<param-value>.xhtml.xml</param-value>
</context-param>
<context-param>
<param-name>faceslets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_RESOLVER_REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>hot-sneaks</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Resources Servlet</servlet-name>
<servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resources Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter>
<filter-name>NoSessionIdFilter</filter-name>
<filter-class>dev.le.tools.servlet.filter.SessionIdFromUrlRemoveFilter</filter-class>
</filter>
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<!-- Spring security filters -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter>
<filter-name>charEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>mvc-dispatcher</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>charEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>NoSessionIdFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="de************" />
<context:component-scan base-package="de************" />
<import resource="datasource-config.xml" />
<import resource="webflow-config.xml" />
<import resource="security-config.xml" />
<mvc:annotation-driven />
<mvc:resources location="/WEB-INF/views/" mapping="/WEB-INF/views/**"/>
<bean id="defaultServletHttpRequestHandler"
class="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" />
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />
<!-- JSF for representation layer. All JSF files under /WEB-INF/views directory -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="cache" value="false" />
<property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".xhtml" />
</bean>
<bean id="userAuthenticationProvider" class="de.wiegand.mytransport.services.impl.UserAuthenticationProvider">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
webflow-config.xml
<bean id="jpaFlowExecutionListener"
class="org.springframework.webflow.persistence.HibernateFlowExecutionListener">
<constructor-arg ref="sessionFactory" />
<constructor-arg ref="transactionManager" />
</bean>
<bean id="facesContextListener"
class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />
<webflow:flow-executor id="flowExecutor">
<webflow:flow-execution-repository
max-executions="0" />
<webflow:flow-execution-listeners>
<webflow:listener ref="facesContextListener" />
<webflow:listener ref="securityFlowExecutionListener" />
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices" base-path="/WEB-INF/flows">
<webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>
<faces:flow-builder-services id="facesFlowBuilderServices"
development="true" />
<faces:resources />
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="order" value="0" />
<property name="flowRegistry" ref="flowRegistry" />
<property name="flowUrlHandler">
<bean class="de.wiegand.mytransport.ui.util.PrettyFlowUrlHandler" />
</property>
</bean>
<bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".xhtml" />
</bean>
<bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
<property name="flowUrlHandler">
<bean class="de.wiegand.mytransport.ui.util.PrettyFlowUrlHandler" />
</property>
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowUrlHandler">
<bean class="de.wiegand.mytransport.ui.util.PrettyFlowUrlHandler" />
</property>
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<bean id="securityFlowExecutionListener"
class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
search.xhtml
<p:fieldset styleClass="fieldset_search" legend="Fahrt suchen">
<h:form id="searchTripForm">
<p:focus />
<h:panelGrid id="searchPanelGrid"
style="margin: 0 auto; margin-top: 25px; text-align: right"
cellspacing="8" columns="3">
<h:panelGroup>
<h:outputText value="Von:" />
<h:outputText style="color:red" value="* " />
</h:panelGroup>
<p:autoComplete id="origin_autocomplete" minQueryLength="3"
rendered="#{empty searchBean.notUniqueOrigins}"
forceSelection="false" queryDelay="300" maxResults="5"
placeholder="PLZ, Stadt oder Statdtteil" charset="UTF-8"
value="#{searchBean.originDisplayNameAndClearGeoLocation}"
required="true" label="Von" title="Absendeadresse eingeben"
tabindex="false"
completeMethod="#{geoNamesService.getGeoNamesByInput}" />
<h:panelGrid rendered="#{!empty searchBean.notUniqueOrigins}"
columns="1">
<h:selectOneMenu
value="#{searchBean.selectedNotUniqueOriginId}"
style="width:200px;" onchange="submit()"
valueChangeListener="#{searchBean.changeSelectedOrigin}">
<f:selectItems value="#{searchBean.notUniqueOrigins}"
var="origin" itemLabel="#{origin.name}, #{origin.zipcode}"
itemValue="#{origin.id}" />
</h:selectOneMenu>
<p:commandLink id="resetOriginToInput" style="margin-right:20px;"
immediate="true" ajax="false" action="resetOriginToInput">
<h:outputText value="zurücksetzen" />
</p:commandLink>
</h:panelGrid>
<h:panelGroup>
<p:message id="originMsg" for="origin_autocomplete" />
<p:tooltip for="origin_autocomplete" styleClass="tooltip"
showEvent="focus" hideEvent="blur" />
</h:panelGroup>
<h:panelGroup>
<h:outputText value="Nach:" />
<h:outputText style="color:red" value="* " />
</h:panelGroup>
<p:autoComplete id="destination_autocomplete" minQueryLength="3"
queryDelay="300"
rendered="#{empty searchBean.notUniqueDestinations}"
forceSelection="false" charset="UTF-8" maxResults="5"
placeholder="PLZ, Stadt oder Statdtteil"
value="#{searchBean.destinationDisplayNameAndClearGeoLocation}"
effect="fade" required="true" label="Nach"
title="Empfängeradresse eingeben"
completeMethod="#{geoNamesService.getGeoNamesByInput}" />
<h:panelGrid
rendered="#{!empty searchBean.notUniqueDestinations}"
columns="1">
<h:selectOneMenu
value="#{searchBean.selectedNotUniqueDestinationId}"
style="width:200px;" onchange="submit()"
valueChangeListener="#{searchBean.changeSelectedDestination}">
<f:selectItems value="#{searchBean.notUniqueDestinations}"
var="destination"
itemLabel="#{destination.name}, #{destination.zipcode}"
itemValue="#{destination.id}" />
</h:selectOneMenu>
<p:commandLink id="resetDestinationToInput" ajax="false"
immediate="true" style="margin-right:20px;"
action="resetDestinationToInput">
<h:outputText value="zurücksetzen" />
</p:commandLink>
</h:panelGrid>
<h:panelGroup>
<p:message id="destinationMsg" for="destination_autocomplete" />
<p:tooltip for="destination_autocomplete" styleClass="tooltip" showEvent="focus" hideEvent="blur" />
</h:panelGroup>
</h:panelGrid>
Controller:
#RequestMapping(value="/", method=RequestMethod.GET)
public ModelAndView init() {
ModelAndView mav = new ModelAndView("suche*");
return mav;
}
#RequestMapping(value="/suche*", method = RequestMethod.GET)
public ModelAndView search(HttpServletRequest request) {
ModelAndView mav = new ModelAndView("views/suche");
return mav;
}
#RequestMapping(value="/suche*", method = RequestMethod.POST)
public ModelAndView _search(SearchRequestBean searchBean, Model model) {
ModelAndView mav = new ModelAndView("views/suche");
return mav;
}
#RequestMapping(value="/detail*", method=RequestMethod.GET)
public ModelAndView detail() {
ModelAndView mav = new ModelAndView("views/detail");
return mav;
}
T hank you very much.

i want to handle database connection exception using spring security

I am getting the following error:- Login error. Reason : Could not get JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'dbname' when i try to connect with wrong database. But i want to handle that exception and want to show some customize message.
Here is my configuration file:-
Spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<!--<http pattern="/abc/**" security="none" /> -->
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/admin*" access="hasRole('SYS_ADMIN')" />
<intercept-url pattern="/cab-stop-admin*" access="hasAnyRole('SYS_ADMIN','CABSTOP_ADMIN')" />
<intercept-url pattern="/driver*" access="hasAnyRole('DRIVER','SYS_ADMIN','CABSTOP_ADMIN')" />
<intercept-url pattern="/customer*" access="hasAnyRole('CUSTOMER','SYS_ADMIN','CABSTOP_ADMIN')" />
<form-login login-page="/login" default-target-url="/role-check"
authentication-failure-url="/login?error=true" />
<remember-me key="_spring_security_remember_me"/>
<logout logout-success-url="/login" />
</http>
<authentication-manager>
<authentication-provider>
<password-encoder hash="md5" />
<jdbc-user-service data-source-ref="fmsDataSource"
users-by-username-query="select Username,Password, 'true' as enabled from login_details where Username=?"
authorities-by-username-query="select u.Username, ur.Role_Name from login_details u, role_master ur where u.Role_Master_Id = ur.Role_Master_Id and u.Username =? " />
</authentication-provider>
</authentication-manager>
</beans:beans>
login.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# page contentType="text/html;charset=UTF-8"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<jsp:include page="header.jsp" />
<html>
<head>
<title><spring:message code="message.home" /></title>
</head>
<body>
<c:if test="${not empty param.error}">
<font color="red"><br /> Login error.
Reason : ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message} </font>
</c:if>
<form name="loginForm" onsubmit="return validateForm();">
<h1><spring:message code="message.login" /></h1>
<table>
<tr>
<td align="right"><spring:message code="message.username"
text="default text" /></td>
<td><input type="text" name="j_username" id="j_username" autofocus="autofocus"/></td>
</tr>
<tr>
<td align="right"><spring:message code="message.password"
text="default text" /></td>
<td><input type="password" name="j_password" /></td>
</tr>
<tr>
<label for='_spring_security_remember_me'>
Remember me:
<input type='checkbox' name='_spring_security_remember_me' value="on"/>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit"
value="<spring:message code="message.login" />" /></td>
<td colspan="2" align="right"><a href="<%=request.getContextPath()%>/customer/register"><spring:message
code="message.register" text="default text" /></a></td>
</tr>
<tr>
<td colspan="2" align="right"><a href="<%=request.getContextPath()%>/forgot-password"><spring:message
code="message.forgotpassword" text="default text" /></a></td>
</tr>
</table>
</form>
</body>
<jsp:include page="footer.jsp" />
</html>
hibernate-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<context:component-scan base-package="com.cabfms.dao"/>
<!-- enable the configuration of transactional behavior based on annotations -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="fmsDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${db.driverClassName}" p:url="${db.url}"
p:username="${db.username}" p:password="${db.password}" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="fmsDataSource" />
<property name="packagesToScan" value="com.cabfms.entities" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="javax.persistence.validation.mode">none</prop>
</props>
<!--<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="javax.persistence.validation.mode">none</prop>
<prop key="hibernate.current_session_context_class">${hibernate.current_session_context_class}</prop>
<prop key="hibernate.connection.pool_size">${hibernate.connection.pool_size}</prop>
<prop key="hibernate.c3p0.min_size">${hibernate.c3p0.min_size}</prop>
<prop key="hibernate.c3p0.max_size">${hibernate.c3p0.max_size}</prop>
<prop key="hibernate.c3p0.timeout">${hibernate.c3p0.timeout}</prop>
<prop key="hibernate.c3p0.max_statements">${hibernate.c3p0.max_statements}</prop>
<prop key="hibernate.c3p0.idle_test_period">${hibernate.c3p0.idle_test_period}</prop>
</props>
--></property>
</bean>
<!--Transaction Manager Added -->
<bean id = "transactionManager" class = "org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name = "sessionFactory" ref = "sessionFactory" />
</bean>
</beans>
web.xml
<web-app>
<display-name>Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/dispatcher-servlet.xml,
/WEB-INF/hibernate-config.xml,
/WEB-INF/spring-security.xml,
/WEB-INF/application-context.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Spring MVC -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<!--<url-pattern>/services/*</url-pattern> -->
<!--<url-pattern>/views/*</url-pattern> -->
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping><!--
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
-->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error-page</location>
</error-page>
</web-app>
You can make your application container handle such exceptions.
Uncaught exceptions within an application can be forwarded to an error page as defined in the deployment descriptor (web.xml).
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error</location>
</error-page>
You just need to put exception type you want to handle and location where user will be forwarded in case of application error.
Remember to make this error page visible to anonymous users in case error happens before successful authentication.
<sec:intercept-url pattern="/error" access="permitAll"/>

PrimeFaces Ajax calls always return a 302 status code with Spring Security

I'm creating a project with Spring 3.2.0, PrimeFaces 3.3.1, Mojarra 2.1.11 and then Spring Security 3.1.1.
My problem is the whenever an ajax call is fired by PrimeFaces, like for example in table pagination, the screen components are not refreshed.
EDIT #4
Whenever an ajax called is fired, an status 302 is returned from the server and the page is refreshed
I think the problem is related to Spring security, this are my settings:
<security:http entry-point-ref="authenticationEntryPoint" pattern="/spring/**">
<security:anonymous />
<security:http-basic />
<security:custom-filter position="FORM_LOGIN_FILTER" ref="authenticationProcessingFilter" />
<security:logout logout-url="/spring/logout" logout-success-url="/spring/login?logout=true" />
<security:intercept-url pattern="/spring/login" access="ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMIN" />
<security:intercept-url pattern="/spring/logoutSuccess" access="ROLE_ANONYMOUS,ROLE_USER,ROLE_CLIENT" />
<security:intercept-url pattern="/spring/intro" access="ROLE_ANONYMOUS,ROLE_USER" />
<security:intercept-url pattern="/spring/flows/admin_main_flow/**" access="ROLE_ADMIN" />
<security:intercept-url pattern="/spring/flows/client_main_flow/**" access="ROLE_CLIENT" />
</security:http>
<security:http security="none" pattern="/javax.faces.resource/**" />
<security:http security="none" pattern="/ajax/**" />
<security:http security="none" pattern="/static/**" />
<security:http security="none" pattern="/resources/**" />
This happen just after the login so I don't think the session should be already expired.
EDIT #4 end
I stripped down the application to a minimum and tried this code:
<h:form id="testAjax" >
<h:panelGrid columns="4" cellpadding="5">
<h:outputLabel for="test" value="test:" style="font-weight:bold"/>
<p:inputText id="test" value="#{testBean.test}" />
<p:commandButton value="Submit" update="#form"/>
<h:outputText value="#{testBean.test}" id="display" />
</h:panelGrid>
</h:form>
note that I double checked that no forms are nested, I tried both "process" and "update" with #form or the elements id.
What happens is that the setter of TestBean is called, the attribute setted, but then the getter is never called again to display the new value. This are the logs on server side:
org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'Spring MVC Dispatcher Servlet' processing POST request for [/TryAjax/spring/WEB-INF/login.xhtml]
org.springframework.web.servlet.handler.SimpleUrlHandlerMapping - Mapping [/WEB-INF/login.xhtml] to HandlerExecutionChain with handler [org.springframework.web.servlet.mvc.UrlFilenameViewController#2f46ccac] and 1 interceptor
org.springframework.web.servlet.mvc.UrlFilenameViewController - Returning view name 'WEB-INF/login' for lookup path [/WEB-INF/login.xhtml]
org.springframework.web.servlet.DispatcherServlet - Rendering view [org.springframework.faces.mvc.JsfView: name 'WEB-INF/login'; URL [/WEB-INF/WEB-INF/login.xhtml]] in DispatcherServlet with name 'Spring MVC Dispatcher Servlet'
org.springframework.faces.support.RequestLoggingPhaseListener - Entering JSF Phase: RESTORE_VIEW 1
org.springframework.faces.mvc.JsfView - Asking faces lifecycle to render
org.springframework.faces.support.RequestLoggingPhaseListener - Entering JSF Phase: RENDER_RESPONSE 6
org.springframework.faces.mvc.JsfView - View rendering complete
org.springframework.web.servlet.DispatcherServlet - Successfully completed request
I fear is a problem of configuration, I followed the basic instruction but then made some modifications to correct some errors, here's the web.xml stripped of some not relevant part
<?xml version = '1.0'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee">
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring_context.xml</param-value>
</context-param>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener </listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/tags/synaptic.taglib.xml</param-value>
</context-param>
<filter>
<filter-name>openSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Resources Servlet</servlet-name>
<servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resources Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
Faces config
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>
other spring flow configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xmlns:faces="http://www.springframework.org/schema/faces"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
http://www.springframework.org/schema/faces
http://www.springframework.org/schema/faces/spring-faces-2.2.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
<faces:resources />
<context:annotation-config />
<context:component-scan base-package="com.synaptic"/>
<bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/flows/*=flowController
</value>
</property>
<property name="defaultHandler">
<bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter">
</bean>
<bean id="faceletsViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
<property name="prefix" value="/WEB-INF/"/>
<property name="suffix" value=".xhtml"/>
</bean>
<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-listeners>
<webflow:listener ref="flowFacesContextLifecycleListener" />
<!-- <webflow:listener ref="facesContextListener"/>-->
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<bean id="flowFacesContextLifecycleListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />
<webflow:flow-registry id="flowRegistry" flow-builder-services="facesFlowBuilderServices">
<webflow:flow-location-pattern value="/WEB-INF/flows/**/*.xml"/>
</webflow:flow-registry>
<bean id="conversionService" class="org.springframework.faces.model.converter.FacesConversionService"/>
<bean id="expressionParser" class="org.springframework.webflow.expression.el.WebFlowELExpressionParser">
<constructor-arg>
<bean class="org.jboss.el.ExpressionFactoryImpl"/>
</constructor-arg>
<property name="conversionService" ref="conversionService"/>
</bean>
<faces:flow-builder-services id="facesFlowBuilderServices" expression-parser="expressionParser" conversion-service="conversionService"/>
</beans>
Please if you see anything wrong or you have any idea help me, this issue is bugging me from days. Thank you!
EDIT #1
I add the code for the backing bean and the webflow code where I declare it:
public class TestBean implements Serializable {
private String test = "xxx";
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
<view-state id="home" view="../views/adminHome.xhtml">
<on-entry>
<evaluate expression="textManager.getTest()" result="viewScope.test"/>
</on-entry>
</view-state>
Now this of testBean is just the simplest test case I can make that doesn't work, the main problem I have is that no ajax call works, for example pagination for tables, adding or removing or modifying an element of a datatable, tabView etc.
I generally create the beans for the page and put them in the viewScope or flowScope, this also for lists of data coming from the database. I tryed also having the bean managed by Spring with scope Session but it doesn't work neither. Another note is that the default value display on the page correctly.
EDIT #2
using firebug and the eclipse debug i see this:
Initial value of TestBean.test is "xxx", I change to aaa and press submit.
An ajax post request is sent to the server:
javax.faces.ViewState e2s1
javax.faces.partial.ajax true
javax.faces.partial.execu... #all
javax.faces.partial.rende... testAjax testAjax:display
javax.faces.source testAjax:testButton
testAjax testAjax
testAjax:test aaa
testAjax:testButton testAjax:testButton
When the POST is sent I firt debug a call to TestBean.getTest() and then a call to TestBean.setTest("aaa") that has the correct value.
At this point I would expect another call to TestBean.getTest() when the response is built but the call does not happens and the response does not contain the correct value but the old value "xxx".
If now I refresh the page the getter is called and the new value "aaa" is displayed correctly.
EDIT #3
I still can sort this out. I noticed now with firebug an unexpected behaviour:
when I click the command button 2 requests are sent to the server, a POST and a GET.
The POST is sent first and return an status "302 Moved Temporarily", then the GET start and return a response without the updated data. Anyone knows what status 302 means in this case and what could be the cause?
Debugging in the same way the primefaces demo only a POST request is fired that return no status 302
Thank you
You need to add a parameter to the flow-executor to disable the redirect to the same state. The configuration becomes:
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-listeners>
<webflow:listener ref="flowExecutionListener" />
<webflow:listener ref="facesContextListener"/>
<!-- <webflow:listener ref="flowFacesContextLifecycleListener" />-->
</webflow:flow-execution-listeners>
<webflow:flow-execution-attributes>
<webflow:redirect-in-same-state value="false"/>
</webflow:flow-execution-attributes>
</webflow:flow-executor>
This prevents the flow executor to refresh the page completely after the ajax request is sent.
When you integrate JSF with Spring then your JSF managed beans become Spring beans. This is why Spring includes their own implementation of an ELResolver so that you can reference these Spring beans from within EL expressions.
Unfortunately though the only scopes that Spring supports out of box are #Request, #Session and #Application.
Fortunately a simple implementation of ViewScope that integrates with Spring can be integrated into your application. Cagatay Civici, the lead developer at PrimeFaces wrote a blog article showing an example of a simple ViewScope implementation that can be easily integrated into your application.
http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/
With a managed bean that is view scoped then your beans will have enough persistence to dynamically render page elements on ajax updates.
<webflow:flow-execution-attributes>
<webflow:redirect-in-same-state value="false"/>
</webflow:flow-execution-attributes>
Solved my problem.
I was using org.springframework.web.servlet.handler.SimpleUrlHandlerMapping for navigation with JSF 1.x RichFaces 3.x.
When moving to JSF 2.x and PrimeFaces/RichFaces 4 the ajax aspects of the DataTables did not work (e.g. displayed but would not sort)
Adding this xml worked like magic (as it would need to since I don't know what I am doing)

Resource Handler problems with JSF2 + Richfaces4 + SpringMVC + WebFlow (SWF)

I've been trying to get the above mentioned setup working for days now with minimal success. My issues appears to be with the resource handler. Ie.
<h:outputStylesheet name="header.css" library="page"/>
does not work, NOR can RichFaces resolve any of the resources it uses internally. So i've done some investigating and the tag above should be resolving to "/project/javax.faces.resource/header.css?ln=page" but it is not. 2 obvious issues are occuring.
1) Something in the Resource Handler chain, possibly the richfaces handler, is expecting a ".jsf" suffix to be added to the requested url, which does happen when using the old EXTERNAL facelets w/ JSF2 & RichFaces 3.3.x, but with Richfaces 4 & builtin facelets that doesn't take place. As a result, one of the handlers (RichFaces' I believe) is stripping the .css suffix off thinking it's an extra suffix like how it used to work. (Consequently this causes missing MIME type errors)
2) When the library & name attributes are resolved, the are resolved under the current path instead of the servlet context root. Ie. it should be resolving to "/project/javax.faces.resource/..." but instead it resolves to "/project/index/javax.faces.resource/..." when viewing a page in the /index directory.
Can anyone please give me some insight here? I'm banging my head against the wall on this one & not making any real ground.
btw here is my basic config....
faces-config.xml
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
web.xml
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</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>
<servlet>
<servlet-name>Spring MVC Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
servlet-context.xml
<beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
<beans:property name="prefix" value="/WEB-INF/content/" />
<beans:property name="suffix" value=".xhtml" />
</beans:bean>
<beans:bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<beans:property name="order" value="2"/>
<beans:property name="flowRegistry" ref="flowRegistry" />
</beans:bean>
<beans:bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<beans:property name="flowExecutor" ref="flowExecutor" />
<beans:property name="ajaxHandler">
<beans:bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler"/>
</beans:property>
</beans:bean>
<beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
<beans:property name="prefix" value="/WEB-INF/content/" />
<beans:property name="suffix" value=".xhtml" />
</beans:bean>
<beans:bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
<beans:bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<beans:property name="order" value="3" />
<beans:property name="alwaysUseFullPath" value="true" />
<beans:property name="mappings">
<beans:value>
</beans:value>
</beans:property>
<beans:property name="defaultHandler">
<beans:bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
</beans:property>
</beans:bean>
webflow-config.xml
<faces:resources/>
<beans:bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>
<flow-executor id="flowExecutor">
<flow-execution-listeners>
<listener ref="facesContextListener"/>
</flow-execution-listeners>
</flow-executor>
<flow-registry id="flowRegistry" base-path="/WEB-INF/content" flow-builder-services="flowBuilderServices">
<flow-location-pattern value="/**/flow.xml" />
</flow-registry>
<flow-builder-services id="flowBuilderServices" development="true" />
Ok so I FINALLY nailed this one... with a little help from Rich Faces. So for anyone who is interested in running JSF2 + Rich Faces + SpringMVC + Spring WebFlow on Tomcat6+, well here is what you need...
WEB.XML
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/appServlet/servletContext.xml</param-value>
</context-param>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.faces.FACELETS_VIEW_MAPPINGS</param-name>
<param-value>*.xhtml</param-value>
</context-param>
servletContext.xml
<mvc:annotation-driven />
<context:component-scan base-package="com.package.subpackage"/>
<mvc:resources location="/" mapping="/resources/**" />
<faces:resources order="0" />
<bean id="flowHandlerMapping"
class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry" />
<property name="order" value="3" />
<property name="defaultHandler" ref="defaultHandler" />
</bean>
<bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
<property name="ajaxHandler">
<bean class="org.springframework.faces.richfaces.RichFacesAjaxHandler" />
</property>
</bean>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
<property name="prefix" value="/WEB-INF/pageContent/" />
<property name="suffix" value=".xhtml" />
</bean>
springmvc-config.xml
<bean name="jsfResourceHandlerHack" class="org.springframework.faces.webflow.JsfResourceRequestHandler" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="1" />
<property name="mappings">
<value>
/rfRes/**=jsfResourceHandlerHack
</value>
</property>
</bean>
spring-webflow-config.xml
<!-- Executes flows: the central entry point into the Spring Web Flow system -->
<flow-executor id="flowExecutor">
<flow-execution-listeners>
<listener ref="facesContextListener"/>
</flow-execution-listeners>
</flow-executor>
<flow-registry id="flowRegistry" base-path="/WEB-INF/content" flow-builder-services="facesFlowBuilderServices">
<flow-location-pattern value="/**/flow.xml" />
<flow-location id="parent-flow" path="parent-flow.xml"/>
</flow-registry>
<faces:flow-builder-services id="facesFlowBuilderServices" development="true"/>
<beans:bean name="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />
spring-beans-config.xml
`
<bean name="defaultHandler" class="org.springframework.web.servlet.mvc.UrlFilenameViewController" >
</bean>`
The Jar versions are as follows...
Spring Core 3.0.5
Spring Web Flow 2.2.1
JSF RI 2.0.3
and most importantly...
Rich Faces 4.0.0.20101226-M5
So the key to making this work seemed to be the version of RichFaces. RichFaces 4 is not production ready yet, so hopefully once that happens everything will be working smoothly but in the meantime, now that Milestone 5 has been released, this setup seems to work. The part to take note of is the JsfResourceHandlerHack mapping. Richfaces attempts to resolve some of its resources (the ones created on the fly I believe) using the keyword "rfRes" by default. The problem I had was the "rfRes" key is not being mapped to the resource handler. There is a way to configure it, but that didn't seem to be working. So the quick fix is to create another resource handler instance and map it manually. So for anyone who is interested, there it is.
I think your question is answered in https://jira.springsource.org/browse/SWF-1366.
Good luck

Resources