【发布时间】:2013-04-10 18:54:35
【问题描述】:
我使用的是 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="display" />
</p:outputPanel>
<p:outputPanel id="display" layout="block">
content 1
</p:outputPanel>
</h:form>
</f:view>
content-2.xhtml:
<h:body>
content 2 loaded
</h:body>
当我点击<p:commandButton> 时,content-2.xhtml 将被打开。但是,这会刷新整个页面。 XML 响应包含如下内容:
<partial-response><changes><update id="javax.faces.ViewRoot">
当我将action 属性更改为方法表达式时:
<f:view>
<h:form id="form1">
<p:outputPanel layout="block">
<p:commandButton action="#{myBean.increment}" update="display" />
</p:outputPanel>
<p:outputPanel id="display" layout="block">
#{myBean.count}
</p:outputPanel>
</h:form>
</f:view>
然后display 块按预期更新。 XML 响应包含如下内容:
<partial-response><changes><update id="form:display">
为什么action="content-2?faces-redirect=false"的方式会更新整个页面?
我也尝试<ui:composition>,但在这种情况下,这会重新加载模板的“静态”部分。我不想要。
【问题讨论】:
-
您是在暗示
#{myBean.method}返回content-2.xhtml?faces-redirect=false已经是默认值了,我不明白你为什么要明确提到这一点。您是在暗示action="content-2.xhtml"的行为不同吗? -
不,抱歉,我确实用#{myBean.method} 更新了部分。方法体看起来像
count++。我尝试action="content-2.xhtml"它也刷新javax.faces.ViewRoot但action="#{myBean.increment}"刷新display。我认为faces-redirect=false必须有分配true或false。