繁体   English   中英

导航后未呈现JSF标记

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM