【发布时间】:2013-07-01 11:25:46
【问题描述】:
我在使用 JSF 测试应用程序和 PrimeFaces 组件时遇到问题,并且找不到错误。
我从一个由以下定义的模板文件 (layoutTempl.xhtml) 开始:
....
<h:body>
<p:layout fullPage="true" >
<p:layoutUnit position="north" size="95" >
<ui:insert name="menubar" >
MenuBar
</ui:insert>
</p:layoutUnit>
<p:layoutUnit position="west" resizable="false" size="250">
<ui:insert name="tree" >
ProjectTree
</ui:insert>
</p:layoutUnit>
<p:layoutUnit position="center">
<ui:insert name="main" >
MainContent
</ui:insert>
</p:layoutUnit>
<p:layoutUnit position="south" size="45">
<ui:insert name="footer" >
Footer
</ui:insert>
</p:layoutUnit>
</p:layout>
</h:body>
....
此模板用于两个页面(indexContent.xhtml):
....
<body>
<ui:composition template="./layoutTempl.xhtml">
<ui:define name="menubar">
MenuBar
</ui:define>
<ui:define name="tree">
Project Tree
</ui:define>
<ui:define name="main">
<ui:include src="index.xhtml"/>
</ui:define>
<ui:define name="footer">
Footer
</ui:define>
</ui:composition>
</body>
....
和(abcContent.xhtml):
....
<body>
<ui:composition template="./layoutTempl.xhtml">
<ui:define name="menubar">
MenuBar
</ui:define>
<ui:define name="tree">
Project Tree
</ui:define>
<ui:define name="main">
<ui:include src="abc.xhtml"/>
</ui:define>
<ui:define name="footer">
Footer
</ui:define>
</ui:composition>
</body>
....
包含的文件 index.xhtml 包含:
....
<h:body>
<ui:composition >
Hello from BareTest
<br /><br />
<h:form id="myform">
<p:selectOneMenu id="scroll2"
value="#{listTestBean.selectedMyObject}" >
<f:selectItems value="#{listTestBean.myObjects}"/>
<p:ajax event="change" listener="#{listTestBean.valueChanged}"/>
</p:selectOneMenu>
<br/><br/>
</h:form>
</ui:composition>
</h:body>
....
而 abc.xhtml 包含:
....
<h:body>
<h2>We got at abc page!</h2>
<br /><br />
<h:form id="abcForm">
<p>#{listTestBean.selectedMyObject}</p>
<p:commandLink id="Ajax" ajax="true" action="indexContent?faces-redirect=false">
<h:outputText value="Main page (link)" />
</p:commandLink>
</h:form>
</h:body>
....
请求范围的托管 bean listTestBean 包含 getter 和 setter 方法以及 valueChanged 方法。 valueChanged 方法成立:
....
try {
FacesContext.getCurrentInstance().getExternalContext().redirect("abcContent.xhtml");
} catch (IOException ioe) {
System.err.println("listTestBean.valueChanged: IOException");
}
....
这基本上是对 abcContent 页面的重定向。
但是,当我从 selectItem 组件中选择一个项目时,abcContent.xhtml 页面没有呈现,具有指定的 layoutTempl?
我完全不明白,对不起!这可能是一件微不足道的事情,但我无法解决它!
问候
【问题讨论】:
-
您是说页面是在没有模板的情况下呈现的,还是根本不呈现?还有你 web.xml 中的 url 模式是什么?
-
它被渲染但没有模板! URL 模式如下所示:
<url-pattern>/faces/*</url-pattern>! -
您的页面可能看不到模板。检查路径,直接加载页面看看。
-
但是为什么使用 layoutTempl 可以正确呈现索引页面?当我在
abcContent.xhtml..之前添加 faces/ 时,页面会正确呈现,但 GlassFish 服务器现在会抛出警告WARNING: JSF1015: Request path '/faces/abcContent.xhtml' begins with one or more occurrences of the FacesServlet prefix path mapping '/faces'。 -
为什么在
abcContent.xhtml中使用<body>标签?
标签: jsf primefaces