JSF + PrimeFaces:"update"属性不会更新组件 [英] JSF + PrimeFaces: `update` attribute does not update component

查看:345
本文介绍了JSF + PrimeFaces:"update"属性不会更新组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的布局

<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:outputTextupdateform周围放置一个表单,那么它将起作用.为什么会这样?

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"属性不会更新组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆