gpt4 book ai didi

jsf - h :commandButton action method not called on request scoped bean

转载 作者:行者123 更新时间:2023-12-04 05:13:22 25 4
gpt4 key购买 nike

我在 jsf 页面上有一个 h:commandButton。并且需要根据条件进行渲染。条件上的属性是页面的隐藏输入。指定渲染条件时,不调用按钮上的 Action 方法。

有任何想法吗?

这是示例代码:

<h:commandButton value="Button" 
action="#{bean.method}"
rendered="#{bean.conditon}"
type="submit"/>

<h:inputHidden value="#{bean.condition}" />

最佳答案

我知道你的 bean 是请求范围的,否则你不会有这个问题。这是一个时间问题。
rendered属性也是在 JSF 生命周期的“应用请求值”阶段确定的。但是,提交的值仅在 JSF 生命周期的“更新模型值”阶段(更晚)在模型中设置。因此,当 rendered属性被评估时,它不会从隐藏的输入中获取提交的值,而是属性的默认值。

如果无法将请求范围更改为 view scope ,那么你需要以不同的方式解决这个问题。更改 <h:inputHidden> 的最简单方法之一成为 <f:param>并通过 @ManagedProperty 注入(inject)值在 #{param} map :

<h:commandButton value="Button" 
action="#{bean.method}"
rendered="#{bean.conditon}"
>
<f:param name="condition" value="#{bean.condition}" />
</h:commandButton>

(请注意,我省略了 type="submit",因为它已经是默认设置了)


@ManagedProperty("#{param.condition}")
private boolean condition;

也可以看看:
  • commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated - 第 6 点
  • 关于jsf - h :commandButton action method not called on request scoped bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14613674/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com