【问题标题】:p:commandButton rendered property doesn't update with ajax [duplicate]p:commandButton 呈现的属性不使用 ajax 更新 [重复]
【发布时间】:2017-10-16 00:03:00
【问题描述】:

来自this answer 我知道了:

您只能对始终呈现的组件进行 ajax 更新(即 当它没有渲染属性时)。

但我尝试了这段代码,但 ajax-update 对我不起作用,我需要刷新浏览器才能看到更改后的按钮。我做错了什么?

<p:outputPanel id="buttonArea">
    <p:panel styleClass="button-area" 
             rendered="#{user != null and loginManager.profile.id != userPage.profile.id}">
        <h:form>
             <p:commandButton styleClass="button-flat" action="#{userPage.followUser}"
                              value="Follow" rendered="#{!userPage.followed}" update="buttonArea"/>
             <p:commandButton styleClass="button-flat" action="#{userPage.unfollowUser}"
                              value="Unfollow" rendered="#{userPage.followed}" update="buttonArea"/>
        </h:form>
    </p:panel>
</p:outputPanel>

编辑:

我尝试了可能重复的问题的解决方案,但它对我也不起作用,我做错了,那里没有解释,我尝试使用 ajax 标签,html 中的 id 正是“buttonArea”但是当我引用 id 时,我什至尝试使用冒号和不使用冒号,我尝试使用片段...

【问题讨论】:

  • 如果我按照答案的建议去做,它怎么可能是重复的?,我引用了一个父组件
  • 是的,动作被调用,数据库被更新,如果我刷新浏览器,变化是可见的。控制台中什么都没有。

标签: primefaces jsf-2 jsf-2.2


【解决方案1】:

您的命令按钮需要自己的 ID。更新它们而不是面板。

【讨论】:

  • 你试过了吗?您不能直接使用动态渲染属性更新元素。
  • 至少不是从“隐藏”到“可见”(反之亦然,或者当它们保持可见时)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-11-26
  • 1970-01-01
  • 2015-08-31
  • 2018-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多