【问题标题】:Change flowScope value with commandButton使用 commandButton 更改 flowScope 值
【发布时间】:2013-04-03 08:40:14
【问题描述】:

我的view-state 中有一个布尔变量:

<set name="flowScope.render" value="false" type="java.lang.Boolean" />

现在我用这个变量渲染一个commandButton

<p:commandButton value="Show Dates"
                            rendered="#{!render}"
                            update="table1,buttons" />

现在我想通过单击此命令按钮来更改变量的值。我尝试了setPropertyActionListener,但它不起作用:

<p:commandButton value="Show Dates" rendered="#{!render}" update="table1,buttons">
    <f:setPropertyActionListener value="true" target="#{render}" />
</p:commandButton>

我没有找到太多关于如何更改值的信息。那么这怎么可能呢?

【问题讨论】:

  • 为什么不设置render="#{someBean.renderValue}"属性,用commandButton设置renderValue值?
  • @pantominas 我已经有了一个 Bean 属性。但问题是,当超过 1 个用户登录时,该值会为所有人更改。所以我应该使用我改变的 flowScope。

标签: jsf primefaces


【解决方案1】:

现在我想通了。
我必须与transitions 合作。在设置变量的同一个view-state 中,我定义了两个transitions

<transition on="rendertrue">
    <set name="flowScope.render" value="true" type="java.lang.Boolean" />
</transition>
<transition on="renderfalse">
    <set name="flowScope.render" value="false" type="java.lang.Boolean" />
</transition>

我不改变存在变量的值,我只是覆盖它。如果这是最好的或清洁的解决方案,我不知道,但它有效。
现在我用commandButton中的action语句调用特定的transition

<p:commandButton value="Show Date"
                            rendered="#{!render}" update="table1,buttons"
                            action="rendertrue" />
<p:commandButton value="Hide Date"
                            rendered="#{render}" update="table1,buttons"
                            action="renderfalse" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2012-06-13
    • 2015-03-26
    • 1970-01-01
    相关资源
    最近更新 更多