valueChangeListener is not getting called from which is placed in side a

前端 未结 1 1904
走了就别回头了
走了就别回头了 2021-01-03 07:15

I am facing an issue with h:selectOneRadio\'s valueChangeListener=\"#{user.loadYesNo}\" (I use Mojarra 2-0-8 on Tomcat-7) . If I remove both the panelGrid enclosing the \'h

相关标签:
1条回答
  • 2021-01-03 08:00

    You need to put the bean in the view scope in order to retain the underlying condition of the rendered attribute for the subsequent requests.

    @ManagedBean
    @ViewScoped
    public class User {
        // ...
    }
    

    Unrelated to the concrete problem, the valueChangeListener is intended to be used whenever you want to have a hook on the server side value change event which allows you to have both the old value and the new value at your hands. For example, to log an event. It's not intended to perform business actions based on the change. For that you should be using the listener attribute of <f:ajax> instead.

    So, replace

    <h:selectOneRadio id="yesNoRadio" value ="#{user.yesNoRadio}" valueChangeListener="#{user.loadYesNo}">
        <f:selectItem itemValue="1"  itemLabel="YES"></f:selectItem>
        <f:selectItem itemValue="0" itemLabel="NO"></f:selectItem>
        <f:ajax event="change" execute="@form" render="userDetailsGrid "></f:ajax>
    </h:selectOneRadio>
    

    with

    <h:selectOneRadio id="yesNoRadio" value ="#{user.yesNoRadio}">
        <f:selectItem itemValue="1"  itemLabel="YES"></f:selectItem>
        <f:selectItem itemValue="0" itemLabel="NO"></f:selectItem>
        <f:ajax execute="@form" listener="#{user.loadYesNo}" render="userDetailsGrid"></f:ajax>
    </h:selectOneRadio>
    

    and remove the ValueChangeEvent attribute from the method.

    0 讨论(0)
提交回复
热议问题