【问题标题】:Template (jsf) is not working properly. When i override the elements, they dont appear on the page.模板 (jsf) 无法正常工作。当我覆盖元素时,它们不会出现在页面上。
【发布时间】:2014-05-25 08:46:50
【问题描述】:

我已经分三步完成了模板:

首先,我创建了一个 xhtml 文件,其中包含所有页面共有的内容:

AllComponentsTemplate.xhtml


<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
 xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:ui="http://java.sun.com/jsf/facelets">

<head>
    <title>State Transport Department- Work Schedule</title>
    <meta name="viewport" content="width=device-width"/>
    <link  rel="stylesheet" type="text/css" href="../../CSS/CompleteTemplateCSS.css"/>
    <link  rel="stylesheet" type="text/css" href="../../CSS/templateCSS.css"/>
</head>

<body>

    <div class="container">
        <div class="header"></div>
        <div class="menu">
<h:outputLabel  class="welcomeNote" value="#{welcomeBean.fullname}" />

         <ul class="ulForMyAccount"><li> <h:outputLabel value="My Account" id="mainAnchor"/>

                            <ul ><li> <a href="/webpages/ChangePasswordxhtml.xhtml"    id="subAnchor"  >Change my Password</a>  </li> </ul></li></ul> </div>

<div class="contentBody">

            <div class="menuTable">
                        <table class="templateBody" >
                            <tr>
                                <td class="navigationLink" > <ul><li>
                                            <h:link  value="Home" outcome="/webpages/NewWelcome.xhtml"  rendered="#{welcomeBean.home}" class="mainLinks"/> 
                                        </li></ul> </td>

                            </tr>  </table>   </div>   </div>

   <div class="footer"></div>

    </div>  </body> </html>

然后我创建了一个 MainTemplate.xhtml 页面,我将在其他页面中将其用作模板:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://xmlns.jcp.org/jsf/html"
 xmlns:f="http://xmlns.jcp.org/jsf/core"
   xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view>

    <h:head>
        <title>State Transport Department-Work Schedule</title>                
    </h:head>

    <h:body>

         <ui:include src="AllComponentsTemplate.xhtml"/>
         <ui:insert name="informationBody"></ui:insert>

     </h:body> </f:view> </html>

然后我将此模板添加到我的第一页 Trial.xhtml

 <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:h="http://xmlns.jcp.org/jsf/html"
                 xmlns:f="http://xmlns.jcp.org/jsf/core"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 template="/webpages/templates/CompleteTemplate.xhtml">

    <ui:define name="informationBody">
        <h:form>
              <h:commandButton id="allocateButton" value="Test Submit" action="#{empDutySchedBean.testMethod}"/>
        </h:form>
    </ui:define>

</ui:composition>

注意:trial.xhtml 没有html、head、body标签。

问题:直到 MainTemplate.xhtml 页面,包括链接等的所有组件都完全可见。 但是在将模板包含到 Trial.xhtml 页面后,我的帐户欢迎标签、主页导航链接没有不出现。

除此之外,我申请的网页背景颜色的所有css都出现了。

我不知道为什么。帮助将不胜感激。我是编码初学者。

谢谢! :)

【问题讨论】:

  • 我已经更新了我的答案,提出了重组的建议。

标签: html jsf jsf-2


【解决方案1】:

将您的AllComponentsTemplate.xhtml 定义为ui:composition 也不需要htmlheadbody,因为AllComponentsTemplate.xhtml 将被包括在内,所以不需要添加template属性,或define 部分。

如果我是你,我会将AllComponentsTemplate.xhtml 设置为它自己的主模板,使用htmlh:headh:body 等,然后让Trial.xhtml 实现它。 稍后,如果您需要其他页面来共享视图,您可以继续创建 AnotherComponentsTemplate.xhtml 并让他们实现它。

【讨论】:

    【解决方案2】:

    请参考此链接,因为您是初学者。

    http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/

    考虑到您的问题,正如 Najjar 在他的回答中提到的那样,对所有 html 标签使用 h:head 和 h:body。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-18
      • 2018-08-09
      • 2012-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多