1 Reply Latest reply on May 3, 2012 10:19 AM by gbalaji2004

    HtmlSelectOneRadio click twice to trigger Valuechangeevent listener

    gbalaji2004

      Hi All,

        I am trying to dynamically create a form which would have a radio button with three choices. The choices are displayed with the radio button but the problem is the ValueChangeEvent is triggered only on clicking the button twice.

       

      My XHTML is :

       

      <h:column>

                                                <h:selectOneRadio id="UserTypeOption" value="#{userRegistrationBean.businessInfo.userType}"

                                                valueChangeListener="#{userRegistrationBean.generateDynamicFormFields}">

                                                 <a4j:ajax event="valueChange" render="supplementQuestionForm1"/>

                                                                    <f:selectItems id="USERTYPE" value="#{userRegistrationBean.userTypeList}"/>

       

                                                                  </h:selectOneRadio>

                                      </h:column>

       

      <h:form id="supplementQuestionForm1" binding="#{userRegistrationBean.supplementQuestionForm1}">

                                      </h:form>

       

      Java code snippet is:

       

      private static org.ajax4jsf.component.behavior.AjaxBehavior

      ajaxBehavior=(org.ajax4jsf.component.behavior.AjaxBehavior

      ) FacesContext.getCurrentInstance().getApplication().createBehavior(

                          org.ajax4jsf.component.behavior.AjaxBehavior.BEHAVIOR_ID);

                 static

                 {

                                    Collection<String> renders = new ArrayList<String>();

                                    ajaxBehavior.addAjaxBehaviorListener(userRegistrationBean.getValueChangeListener());--Value change listener is attached to the Ajax Behaviour.

                                    renders.add("supplementQuestionForm1");

        ajaxBehavior.setRender(renders);

        }

       

       

      //Declare radio and add items

      HtmlSelectOneRadio radio= (HtmlSelectOneRadio) FacesContext.getCurrentInstance().getApplication().createComponent(HtmlSelectOneRadio.COMPONENT_TYPE);

      ArrayList<SelectItem> radioBtnOptionsList = new ArrayList<SelectItem>();

      radioBtnOptionsList.add(new SelectItem("TEST1","TEST1));

      radioBtnOptionsList.add(new SelectItem("TEST2","TEST2));

      radioBtnOptionsList.add(new SelectItem("TEST3","TEST3));

       

      //Add options to SelectItems

      UISelectItems radioBtnOptions = (UISelectItems) FacesContext.getCurrentInstance().getApplication().createComponent(UISelectItems.COMPONENT_TYPE);

      radioBtnOptions.setValue(radioBtnOptionsList);

       

      radio.addClientBehavior("valueChange", ajaxBehavior);

      radio.getChildren().add(radioBtnOptions);

       

       

      Please throw some light as to why the valurchange event is fired only after the second click. Thanks,GB

       

      I am using RF 4.2, JSF 2 running on Websphere 7 in RAD 8.