I am actually trying to do a web application using JSF, and I have some issue with the rendering in the web browser.
Here is the context :
I have an index.xhtml page which displays correctly the JSF tags, and I want to navigate to another through a simple hyperlink.
<h:outputLink value="/Advisor/AddClient.xhtml">
<h:outputText value="Add a client" /> </h:outputLink>
But then, the AddClient page doesn't displays the result of the JSF tags as it should.
Here is the addclient file :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<h:body>
<ui:composition template="template.xhtml">
<script type="text/javascript">
<!-- a validation script used in py page -->
</script>
<h:panelGroup layout="block" rendered="#{loginBean.isLogged}">
<h:form id="formu" onsubmit="return validation()">
<table>
<tr>
<td>
First name :
</td>
<td>
<h:inputText id="txtFName" value="#{clientCreationBean.fname}"/>
</td>
</tr>
<tr>
<td>
Last name :
</td>
<td>
<h:inputText id="txtLName" value="#{clientCreationBean.lname}"/>
</td>
</tr>
<tr>
<td>
E-Mail :
</td>
<td>
<h:inputText id="txtEmail" value="#{clientCreationBean.email}"/>
</td>
</tr>
<tr>
<td>
Address :
</td>
<td>
<h:inputText id="txtAddress" value="#{clientCreationBean.address}"/>
</td>
</tr>
<tr>
<td>
Zip code :
</td>
<td>
<h:inputText id="txtZip" value="#{clientCreationBean.zip}"/>
</td>
</tr>
<tr>
<td>
City :
</td>
<td>
<h:inputText id="txtCity" value="#{clientCreationBean.city}"/>
</td>
</tr>
<tr>
<td>
Phone :
</td>
<td>
<h:inputText id="txtPhone" value="#{clientCreationBean.phone}"/>
</td>
</tr>
</table>
<h:commandButton action="#{clientCreationBean.CreateClient()}" value="Ajouter"/>
</h:form>
</h:panelGroup>
</ui:composition>
</h:body>
</html>
and here is my web.xml :
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
Any idea of why the JSF is not interpreted in my others pages?
UPDATE :
I got AddClient to work like this :
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Moving AddClient.xhtml to the same folder than Index.xhtml (and not in the "Advisor" folder anymore), and changing my link to :
<h:outputLink value="AddClient.xhtml">
<h:outputText value="Ajouter un client" />
</h:outputLink>
But when I let the page in the Advisor folder with a link poiting at /Advisor/AddClient.xhtml, it doesn't work. why?
Thanks,
KiTe
Your link doesn't match the faces servlet mapping:
<h:outputLink value="/Advisor/AddClient.xhtml">
will not match the pattern:
/faces/*
That's why the FacesServlet will not be invoked and your JSF tags are not processed.
You can either change the link to:
<h:outputLink value="/faces/Advisor/AddClient.xhtml">
or better use the .xhtml suffix mapping to in your web.xml :
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.