![](/img/trans.png)
[英]ViewExpiredException on every navigation after migrating from JSF 1.2 to JSF 2.0
[英]JSF tag not rendered after navigation
我實際上是嘗試使用JSF做一個Web應用程序,我在Web瀏覽器中的渲染有一些問題。
以下是上下文:
我有一個index.xhtml頁面,它正確顯示JSF標記,我想通過一個簡單的超鏈接導航到另一個。
<h:outputLink value="/Advisor/AddClient.xhtml">
<h:outputText value="Add a client" /> </h:outputLink>
但是,AddClient頁面不會顯示JSF標記的結果。
這是addclient文件:
<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>
這是我的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>
知道為什么JSF沒有在我的其他頁面中解釋?
更新:
我讓AddClient像這樣工作:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
將AddClient.xhtml移動到與Index.xhtml相同的文件夾(而不再是“Advisor”文件夾中),並將我的鏈接更改為:
<h:outputLink value="AddClient.xhtml">
<h:outputText value="Ajouter un client" />
</h:outputLink>
但是當我讓Advisor文件夾中的頁面與/Advisor/AddClient.xhtml中的鏈接相關時,它不起作用。 為什么?
謝謝,
風箏
您的鏈接與面部servlet映射不匹配:
<h:outputLink value="/Advisor/AddClient.xhtml">
將不符合模式:
/faces/*
這就是為什么不會調用FacesServlet並且不處理您的JSF標記的原因。
您可以將鏈接更改為:
<h:outputLink value="/faces/Advisor/AddClient.xhtml">
或者更好地在web.xml中使用.xhtml后綴映射:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.