我使用 Facelets 模板完成了一个基本的 JSF 应用程序。我的模板如下:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<!-- Links to CSS stylesheets... -->
<title><ui:insert name="title" /> - FManager</title>
</h:head>
<h:body>
<div id="wrapper">
<div id="header"> <b>FManager</b> Application </div>
<div id="content">
<p:growl id="growl" />
<ui:insert name="content">
Sample content.
</ui:insert>
</div>
</div>
<div id="footer">Made using JSF and Primefaces</div>
</h:body>
</html>
然后我有一个主页(如下所示)导航到第二页。两个页面都使用上面的模板。
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
template="./template.xhtml">
<ui:define name="title">Main page</ui:define>
<ui:define name="content">
<h2>Welcome to the <b>FManager</b> application</h2>
<h:form>
<p>Click the button below to create the first entry!</p>
<p:commandButton value="Create entry" action="create" />
</h:form>
</ui:define>
</ui:composition>
如果我使用<redirect/>
在 faces-config.xml 中,它进行导航,但是full页面已重新加载。我的问题是:
有没有办法从一个页面导航到另一个页面,仅更新<ui:insert>
模板的各个部分?(同时保持页面的其余部分完好无损)
Thanks!
您可以通过ajax重新加载内容,但URL将保持不变。如果您负担得起,请按如下方式更新代码:
In template.xhtml
, 代替
<div id="content">
by
<h:panelGroup id="content" layout="block">
And in somepage.xhtml
, 代替
<p:commandButton value="Create entry" action="create" />
by
<p:commandButton value="Create entry" action="create" update=":content" />
终于摆脱了<redirect />
(其实更喜欢get rid所有导航案例,因为他们使faces-config.xml
文件臃肿)。顺便说一句,重定向也可以在结果中指定,如下所示action="create?faces-redirect=true"
.
这只是不更新<title>
。不过,您可以使用简单的 JavaScript 行来做到这一点。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)