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

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

问题描述

这是我的布局

<div id="填充"><h:outputText id="text" value="Personal Feed" render="#{Profile.renderComment}"/>

<div id="右"><h:形式><p:commandButton value="Update" actionListener="#{bean.toggleComment}" update="text"/></h:form>

当我点击链接 Update 时,它应该打开和关闭 renderComment 布尔值,它不会切换文本 Personal Feed 的显示.现在,如果我在 h:outputText 周围放置一个表单,然后将 update 替换为 form,那么它就可以工作了.这是为什么?

解决方案

update 属性应该指向 HTML DOM 树中的现有客户端 ID.但是,由于该元素在 HTML DOM 树中不可用,因为它不是由服务器端渲染的,因此 JS/ajax 无法在 HTML DOM 树中找到任何要更新的内容.

实际上,您应该将它包装在另一个始终在 HTML DOM 树中可用的元素中,以便 Ajax 可以找到它,然后在 update 中使用它的客户端 ID.在您的情况下,您可以为此使用 padding.

<h:panelGroup id="padding" layout="block"><h:outputText id="text" value="Personal Feed" render="#{Profile.renderComment}"/></h:panelGroup><div id="右"><h:形式><p:commandButton value="Update" actionListener="#{bean.toggleComment}" update=":padding"/></h:form>

Here is my layout

<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>

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?

解决方案

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.

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天全站免登陆