I'm new to both JSF and Spring Framework and I'm trying to figure out how to make them work together. My current problem is that application outputs my JSF files without interpreting them. Here are some snippets of my code which I believe might be relevant:
dispatcher-servlet.xml
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="login.htm">loginController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/pages/"
p:suffix=".xhtml" />
<bean name="loginController" class="controller.LoginController" />
loginController
public class LoginController extends MultiActionController {
public ModelAndView login(HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("LOGIN");
return new ModelAndView("login");
}
WEB-INF/pages/login.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>#{message.log}</title>
</h:head>
<h:body>
<h:form>
<h:outputLabel value="#{message.username}" for="userName">
<h:inputText id="userName" value="#{User.name}" />
</h:outputLabel>
<h:commandButton value="#{message.loggin}" action="#{User.login}" />
</h:form>
</h:body>
</html>
Any ideas where the problem might be? Does this code make any sense at all? I'm well aware of fact, that probably completely sucks and I'll be glad to here WHY it sucks and how to make it better. Thanks :)
EDIT: I'm adding piece of code which seems to be the root of the problem and which I (of course) didn't include in the original question:
web.xml
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</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>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
The url-pattern of Faces Servlet had to be changed to *.xhtml in order to work properly.
If the JSF tags are not been parsed, then it simply means that the request URL did not match the
url-pattern
of theFacesServlet
as definied inweb.xml
. It is namely responsible for all that JSF happenings. You need to verify if the request URL matches theurl-pattern
of theFacesServlet
. If it is for example*.jsf
, then you need to invoke it byhttp://example.com/context/page.jsf
and thus not byhttp://example.com/context/page.xhtml
.I am however not sure how Spring fits in the picture since I don't use it, but to get JSF to work you really need to pass the request through the
FacesServlet
first, not through some Spring controller. Spring should do its job thereafter.