【问题标题】:<h:outputText> rendered the old value even after ajax update [duplicate]<h:outputText> 即使在 ajax 更新后也呈现旧值 [重复]
【发布时间】:2014-11-26 01:35:24
【问题描述】:

在下面的代码中,我单击提交按钮。通过ajax 调用将backing_home bean 中的boolean result 值更改为true

如果我删除呈现的rendered="#{backing_home.result}",我会正确看到更新后的输出。 但是下面的代码是false。我认为它不会呈现新值

<h:commandButton id="MySubmit" value="Submit" action="#{backing_home.toggleRenderResult}">
   <f:ajax render=":AjaxGuess:result2"/>
</h:commandButton>
<h:outputText id="result2" value="#{backing_home.result}" rendered="#{backing_home.result}" />

可能是什么原因?

【问题讨论】:

  • 这是一个常见的错误,您应该在 panelGroup 中包含 outputText 并改为更新 panelGroup...
  • @Hatem Alimam 我可以知道为什么吗?
  • 因为如果值为 false,则 outputText 将不存在,如果不存在,即使值为 true,它也可以更新。因此,您必须有一个始终存在的元素来更新,即 panelGroup。
  • @HatemAlimam Grate 解释一下。谢谢你。我得到了它。非常合乎逻辑。

标签: jsf facelets


【解决方案1】:

我根据 Hatem Alimam 的评论更新代码如下。

<h:commandButton id="MySubmit" value="Submit" action="#{backing_home.toggleRenderResult}">
   <f:ajax render=":AjaxGuess:result2"/>
</h:commandButton>
<h:panelGroup id="result2">
  <h:outputText value="#{backing_home.result}" rendered="#{backing_home.result}" />
</h:panelGroup>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    • 2019-06-16
    • 1970-01-01
    • 1970-01-01
    • 2017-10-16
    • 1970-01-01
    • 2021-04-04
    相关资源
    最近更新 更多