JSF + Spring MVC and commandLink?
843842Nov 3 2006 — edited Nov 7 2006Hi,
I have my index.jsp page with redirect to jsp/AllAccounts.cmd page. Then I have my own jsp page (jsp/AllAccounts.jsp) with
<h:commandLink id="goToAddNew" action="goToAddNew" value="New Account" />
In web-servlet.xml I use
<bean id="allController" class="web.AllController">
</bean>
<bean id="addController" class="web.AddNewController">
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/jsp/</value>
</property>
<property name="suffix">
<value>.jsf</value>
</property>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="jsp/AllAccounts.cmd">allController</prop>
<prop key="jsp/AddNew.cmd">addController</prop>
</props>
</property>
</bean>
In 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>
<servlet-name>web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>SpringContextServlet</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</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-mapping>
<servlet-name>web</servlet-name>
<url-pattern>*.cmd</url-pattern>
</servlet-mapping>
and faces-config.xml:
<application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
</application>
<navigation-rule>
<display-name>jsp/AllAccounts</display-name>
<from-view-id>/jsp/AllAccounts.jsp</from-view-id>
<navigation-case>
<display-name>jsp/AddNew</display-name>
<from-outcome>goToAddNew</from-outcome>
<to-view-id>/jsp/AddNew.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
Then I have AllController and AddController classes (Controller is org.springframework.web.servlet.mvc.Controller):
public class AllController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// creating and preparing allModel
return new ModelAndView("AllAccounts", "allModel", allModel);
}
}
public class AddNewController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// creating and preparing addModel
return new ModelAndView("AddNew", "addModel", addModel);
}
}
Now the problem: when AllAccounts.cmd page is presented in the web browser, everything is ok, but when I hover over commandLink I can see that it is pointing to AddAccount.jsf page although I would like it to point to AddAccount.cmd page (so it would be intercepted by Spring mappings and correct view would be returned from appropriate spring controller). I've already tried to change extensions in faces-config's navigation rules to *.jsf, jsp, .cmd of both from-view and to-view, but the link is always rendered to *.jsf. Is there any way to force this commandLink to be pointing to *.cmd page?
If it is not possible to configure it in any *.xml file maybe it can be done programatically with bean actions (any example)? I'm new to JSF and Spring, so I would appreciate step-by-step answer. I'm using Eclipse, JSF 1.1 and Tomcat 5.5
Second problem, maybe simpler. When I open my web application, index.jsp will redirect me to AllAccounts.cmd page (http://localhost/webapp/). In that page I use css stylesheets and everything is displayed with styles. But when I invoke directly AllAccounts.cmd page (http://localhost/webapp/jsp/AllAccounts.cmd) all my styles are lost. I use
<link rel="stylesheet" href="css/coa.css"/>
in my *.jsp page. Any clues?
Regards,
morhen