I got it running so far that:
- Dispatcher Servlet is used for applying Spring @Controller
- The JSF-view selected by the controller is correctly rendered by JSF + Richfaces
- No Webflow is used
But I have still strong problems:
When Richfaces renders a reference to a resource for AJAX requests (usually the current page), this is the path where the XHTML-file is. I would require it to be the same path that the user requested originally, the same that matched my @RequestMapping annotation.
Example:
The user requests /spring/test/1 -> Resolved by Spring MVC to /WEB-INF/pages/test_1.xhtml
All AJAX calls from richfaces on this page will request /WEB-INF/pages/test_1.xhtml directly and get a 404 error. Instead, it should request the same /spring/test/1 URL.
I used a lot from the "Hotel Booking Sample" application, and there this seems to work. So I really begin to think that JSF2 or RF3.3.3 could be the problem here...
Again, I would be grateful to get some help.
Here are some relevant snippets:
controller:
Code:
@RequestMapping("/test/{nr}")
public String test(@PathVariable("nr") Long number) {
if (number == null) {
return null;
}
return "test_" + number;
}
Web.xml
Code:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/spring-config.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>/WEB-INF/spring/spring-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
<!-- default suffix for requested pages -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<!-- filter for richfaces integration -->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<!-- integrates richfaces into spring requests -->
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<!-- integrates richfaces into jsf requests -->
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
spring-config.xml
Code:
<!-- Activates annotation-based bean configuration -->
<context:annotation-config />
<!-- Scans for application @Components to deploy -->
<context:component-scan base-package="com.any" />
<!-- Maps logical view names to Facelet templates (e.g. 'search' to '/WEB-INF/pages/search.xhtml' -->
<bean id="jsfViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".xhtml" />
</bean>