模板(jsf)无法正常工作.当我覆盖元素时,它们不会出现在页面上. [英] Template (jsf) is not working properly. When i override the elements, they dont appear on the page.
问题描述
我已通过3个步骤完成了模板:
I have done template in 3 steps:
首先,我创建了一个xhtml文件,该文件的所有页面都具有相同的内容:
Firstly i created a xhtml file with content that is common to all the pages:
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 页面,该页面将在其他页面中用作模板:
Then i created a MainTemplate.xhtml page which i would be using in other pages as templates:
<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
Then i added this template to my first page 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 标签.
Note: trial.xhtml doesn't have a html, head, body tag.
问题:直到MainTemplate.xhtml页面上的所有组件(包括链接等)都清晰可见. 但是在将模板包含到Trial.xhtml页,我的帐户,欢迎标签,首页导航链接之后,没有出现.
Problem: till the MainTemplate.xhtml page, all the components including the link etc were perfectly visible. However after including the template into Trial.xhtml page, The My Account, Welcome label, Home naviagation link didn't appear.
除此之外,我申请网页背景色的所有CSS都出现了.
Apart from this, all the css i applied for the webpage's background color appeared.
我不知道为什么.帮助将不胜感激.我是编码的初学者.
I dont know why. Help would be dearly appreciated. I am a beginner at coding.
谢谢! :)
推荐答案
也将AllComponentsTemplate.xhtml
定义为ui:composition
,它不需要html
,head
和body
以及AllComponentsTemplate.xhtml
将包含在内,无需添加template
属性或define
部分.
Define your AllComponentsTemplate.xhtml
as ui:composition
as well it doesn't need html
, head
and body
, and as AllComponentsTemplate.xhtml
will be included, it doesn't need to add template
attribute, or define
sections.
如果我是我,我会将AllComponentsTemplate.xhtml
设置为主要模板,并使用html
,h:head
和h:body
等进行设置,然后让Trial.xhtml
实现它.
稍后,如果需要其他页面共享视图,则继续创建AnotherComponentsTemplate.xhtml
并让他们实现.
If i were you I would set AllComponentsTemplate.xhtml
as the main template it self with html
, h:head
and h:body
, etc.., and let Trial.xhtml
implement it.
Later on if you needed another pages to have a shared view, you go ahead and create AnotherComponentsTemplate.xhtml
and let them implement it.
这篇关于模板(jsf)无法正常工作.当我覆盖元素时,它们不会出现在页面上.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!