问题描述
这是我的布局
<div id="mainPanel">
<div id="padding">
<h:outputText id="text" value="Personal Feed" rendered="#{Profile.renderComment}"/>
</div>
<div id="right">
<h:form>
<p:commandButton value="Update" actionListener="#{bean.toggleComment}" update="text" />
</h:form>
</div>
</div>
当我单击链接Update
时,该链接应该打开和关闭renderComment
布尔值,它不会切换文本Personal Feed
的显示.现在,如果我在h:outputText
和update
和form
周围放置一个表单,那么它将起作用.为什么会这样?
When I click the link Update
, which is supposed to toggle the renderComment
boolean on and off, it does not toggle the display of the text Personal Feed
. Now if I put a form around the h:outputText
, and update
the form
instead, then it works. Why is that?
推荐答案
update
属性应指向HTML DOM树中的现有客户端ID.但是,由于该元素在服务器端未呈现,因此在HTML DOM树中不可用,因此JS/ajax在HTML DOM树中找不到要更新的任何内容.
The update
attribute should point to an existing client ID in the HTML DOM tree. However, since the element is not available in the HTML DOM tree because it's not rendered by the server side, JS/ajax cannot find anything in HTML DOM tree to update.
实际上,您应该将其包装在HTML DOM树中始终可用的另一个元素中,以便Ajax可以找到它,然后在update
中使用其客户端ID.您可以使用padding
来实现.
In fact, you should wrap it in another element which is always available in the HTML DOM tree so that Ajax can locate it and then use its client ID in update
. In your case, you can use padding
for this.
<div id="mainPanel">
<h:panelGroup id="padding" layout="block">
<h:outputText id="text" value="Personal Feed" rendered="#{Profile.renderComment}"/>
</h:panelGroup>
<div id="right">
<h:form>
<p:commandButton value="Update" actionListener="#{bean.toggleComment}" update=":padding" />
</h:form>
</div>
</div>
这篇关于JSF + PrimeFaces:"update"属性不会更新组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!