【发布时间】:2011-10-12 20:35:16
【问题描述】:
我一直在努力让它工作 2 周,我正在尝试将来自 BalusC 的信息从这 2 个帖子合并到 (link1link2) 以通过菜单实现中心内容区域的部分页面呈现左边。因此,左侧的链接将通过使用<f:ajax> 或可能通过richfaces 的<a4j:ajax> 部分页面呈现来更新中心内容
我的 page-layout.xhtml(include1.xhtml、include2.xhtml、..使用的主模板)看起来像这样。
<h:body>
<div id="top" class="top">
<ui:insert name="top">page-layout default top content</ui:insert>
</div>
<div>
<div id="left">
<h:form id="navigationFormId">
<f:ajax render=":contentForm">
<h:commandLink value="include1"
action="#{navigationBean.setPage('include1')}" />
<p></p>
<h:commandLink value="include2"
action="#{navigationBean.setPage('include2')}" />
<p></p>
<h:commandLink value="include3"
action="#{navigationBean.setPage('include3')}" />
<p></p>
</f:ajax>
</h:form>
</div>
<div id="content">
<ui:insert name="content">
<h:panelGroup id="contentPanelGroup" layout="block">
<h:form id="contentForm">
<h:panelGroup rendered="#{navigationBean.page == 'include1'}">
<ui:include src="include1.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{navigationBean.page == 'include2'}">
<ui:include src="include2.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{navigationBean.page == 'include3'}">
<ui:include src="include3.xhtml" />
</h:panelGroup>
</h:form>
</h:panelGroup>
</ui:insert>
</div>
</div>
</h:body>
NavigationBean.java 通过带有@Named 的 CDI 定义为 ViewScoped bean
公共类 NavigationBean 实现可序列化 {
public NavigationBean() {}
public String getPage() {return page;}
public void setPage(String p) {page = p;}
private String page = "include1";
}
包含的页面是include1.xhtml和include2.xhtml之类的文件,点击左侧菜单链接时应该加载到中心内容,这里是一个示例include2.xhtml
<h:body>
<ui:composition template="page-template.xhtml">
<ui:define name="content">
include2
<h:form>
form components for include2
</h:form>
</ui:define>
</ui:composition>
</h:body>
我得到 FileNotFoundException,虽然堆栈跟踪没有 告诉哪个,但删除
<h:panelGroup rendered=".....>
<ui:include src="..." />
</h:panelGroup>
tags 删除异常。我认为这是基于 2 篇 BalusC 帖子完成此任务的正确实现,但无法使其正常工作。
【问题讨论】:
-
您的模板方法令人困惑且不明智。我的印象是你误解了this answer的最后一段。我并不是说你应该混合使用这两种方法。我的意思是你应该使用一个 或 另一个。我建议还原更改,以便您最终得到与答案中所示相同的示例(或者忘记 ajax 加载并使用普通链接的纯主模板方法)。
-
是的 BalusC,这正是我从你在帖子的最后一段中想到的,它没有说使用一个或另一个,所以我认为我可以使用这种方法的模板。所以让我问这个。通过 facelets 模板渲染部分页面是否容易完成。我看到richfaces 展示和icefaces 展示这样做,但primefaces 在单击左侧链接时会刷新整个页面。顺便提一句。如果想法是结合模板和你建议的方式来做 ppr 是明智的 :-)
-
你可以组合它们,但不能这样。
<ui:insert name="content">在一个不明智的地方。此外,我认为您的意思是使用template="page-layout.xhtml"而不是template="page-template.xhtml"(并不是说这会像您期望的那样工作,但这至少是 FNFE 的原因)。 -
BalusC,你说得对,谢谢指正。我在帖子中有错字。 IncludedX.xhtml 应该引用模板名称 page-layout.xhtml。你能给我举个例子,说明如何将它们结合起来,用菜单/内容设计完成部分页面渲染的 faeclets 版本。我真的很挣扎如何做到这一点,并愿意阅读和调查,只是找不到一个简洁地展示如何做的地方。顺便说一句,感谢您花时间回复,我很感激并阅读了你们中的许多博客和帖子
标签: ajax templates jsf render partial