2
<h:form>
    <h:messages />
        <h:selectOneRadio value="#{bean.selectedValue}" id="selectId"
            layout="pageDirection">
            <f:selectItems value="#{bean.values}" var="value"
                itemLabel="#{value.text}" itemValue="{value}" />
        </h:selectOneRadio>
        <h:commandButton value="Press Me" >
            <f:ajax listener="#{bean.btn_action}" execute="@form"/>
        </h:commandButton>
</h:form>

Below are code details.

  • Bean is backing bean in @ViewScope.
  • bean.values is list of another managed bean which is in @RequestScope.
  • Radio button value is binded to above @RequestScope managed bean in backing bean. #{bean.selectedValue}
  • selectedValue is reference to object in backing bean having getter/setter.

Issues. - When execute=@form is added to ajax tag, listener is not even called. - After execute-@form, listener is getting called however radio button selected value is not updated in backing bean. - When i debug getter is always called for selectedValue never the setter.

Any help will be appreciated. Thanks.

4

1 回答 1

3

假设这itemValue="{value}"只是一个粗心的错字并且您从未注意服务器日志,那么如果#{value}表示非标准类型并且您没有Converter该类型或没有equals()正确实现该类型的方法,则此构造将静默失败.

第一步是添加render="@form"<f:ajax>,以便<h:messages>更新,这样您就不需要查看服务器日志中的转换/验证错误。

<f:ajax execute="@form" listener="#{bean.btn_action}" render="@form" />

第二步是根据显示的转换/验证错误解决问题。很可能您有一个转换错误“空转换器”,或者您可能已经有一个,但是您收到了一个验证错误“值无效”

以下答案详细回答了这两个潜在问题:

于 2012-11-28T12:29:37.217 回答