Ajax 带有面重定向的部分页面呈现(PPR)
我使用的是PrimeFaces 3.5,我遇到了部分页面呈现的问题。我需要将内容从Facelet文件加载到模板的“动态”部分Ajax 带有面重定向的部分页面呈现(PPR),ajax,jsf-2,Ajax,Jsf 2,我使用的是PrimeFaces 3.5,我遇到了部分页面呈现的问题。我需要将内容从Facelet文件加载到模板的“动态”部分 index.xhtml: <f:view> <h:form id="form1"> <p:outputPanel layout="block"> <p:commandButton action="content-2?faces-redirect=false" update="dis
index.xhtml
:
<f:view>
<h:form id="form1">
<p:outputPanel layout="block">
<p:commandButton action="content-2?faces-redirect=false" update="display" />
</p:outputPanel>
<p:outputPanel id="display" layout="block">
content 1
</p:outputPanel>
</h:form>
</f:view>
<h:body>
content 2 loaded
</h:body>
当我点击
时,就会打开content-2.xhtml
。但是,这会刷新整个页面。XML响应包含如下内容:
<partial-response><changes><update id="javax.faces.ViewRoot">
<partial-response><changes><update id="form:display">
然后,显示
块按预期更新。XML响应包含如下内容:
<partial-response><changes><update id="javax.faces.ViewRoot">
<partial-response><changes><update id="form:display">
为什么action=“content-2?faces redirect=false”
方式会更新整个页面
我还试图
,但在本例中,这会重新加载模板的“静态”部分。我不想要它。如果您通过在操作
属性中提供非null
结果来导航到不同的视图,这是完全正常和预期的行为。然后,JSF将以@all
的呈现方式否决部分呈现。JSF/Facelets不会像您预期的那样自动地在树中保留公共组件。如果要在部分页面呈现期间动态更改组件树,则需要在
中包含以下动态内容(部分
只是一个整数)
或多个有条件渲染的节
<ui:fragment rendered="#{bean.section == 1}"><ui:include src="section1.xhtml" /></ui:fragment>
<ui:fragment rendered="#{bean.section == 2}"><ui:include src="section2.xhtml" /></ui:fragment>
<ui:fragment rendered="#{bean.section == 3}"><ui:include src="section3.xhtml" /></ui:fragment>
<ui:fragment rendered="#{bean.section == 4}"><ui:include src="section4.xhtml" /></ui:fragment>
根据include文件是否包含表单/输入/命令组件和/或引用视图范围的bean,每个bean都有自己的优缺点。
在视图构建期间运行,就像JSTL一样。有关更多详细信息,请参见
faces redirect=false的存在并不重要,因为它已经是默认值。如果为true
,则会在目标URL上调用JavaScript窗口.location
。您是否暗示#{myBean.method}
返回content-2.xhtml
?faces redirect=false
已经是默认值了,我不明白你为什么要明确提到这一点。您是在暗示action=“content-2.xhtml”
的行为不同吗?不,抱歉,我用35;{myBean.method}更新了部分。方法主体看起来像count++
。我尝试了action=“content-2.xhtml”
它的刷新javax.faces.ViewRoot
但是action=“#{myBean.increment}”
刷新显示。我认为faces redirect=false
必须有赋值true
或false
。谢谢,我现在明白了。我想我该怎么做,页面上的所有块可能会独立于服务器的状态进行更新。