1 Reply Latest reply on Oct 28, 2010 7:54 AM by shikida

    ValueChangeEvent returns null for dynamically generated SelectItems

    shikida

      I have a JSF page with three dynamically generated combos. One must update the other and so on. Scope is request+keepAlive.

       

      Components does work, so the first combo is selected, the second is updated. Then I select the second and the event defined in the listener is called. But for some reason, the ValueChangeEvent comes null.

       

      First combo (works like a charm)

       

      HtmlSelectOneMenu listaRegiao = (HtmlSelectOneMenu)application.createComponent(HtmlSelectOneMenu.COMPONENT_TYPE);
      listaRegiao.setId(...);
      UISelectItems selectItemsRegiao = (UISelectItems)application.createComponent(UISelectItems.COMPONENT_TYPE);
      List<SelectItem> opcoes = new ArrayList<SelectItem>();

      (add some options here...)

      listaRegiao.getChildren().add(selectItemsRegiao); 
      fieldsetSecao.getChildren().add(listaRegiao);
      listaRegiao.addValueChangeListener(...);
      listaRegiao.setValueExpression("value",...);

      UIAjaxSupport ajaxR =(UIAjaxSupport)application.createComponent(UIAjaxSupport.COMPONENT_TYPE);
      ajaxR.setEvent("onchange");    
      ajaxR.setReRender("secondCombo");
      listaRegiao.getChildren().add(ajaxR);

       

      Second combo (is updated by the first combo, but does not send the new value to the listener method)

       

       

      HtmlSelectOneMenu listaUF = (HtmlSelectOneMenu)application.createComponent(HtmlSelectOneMenu.COMPONENT_TYPE);
      listaUF.setId("secondCombo");
      UISelectItems selectItemsUF = (UISelectItems)application.createComponent(UISelectItems.COMPONENT_TYPE);
      List<SelectItem> opcoesUFBinding = new ArrayList<SelectItem>();

      (add some options here...)

      selectItemsUF.setValue(opcoesUFBinding); //if I comment this, JSF complains that it expects UISelectItems
      selectItemsUF.setValueExpression("value",...);

      listaUF.addValueChangeListener("someMethodHere");
      listaUF.setValueExpression(...);
      UIAjaxSupport ajaxUF =(UIAjaxSupport)application.createComponent(UIAjaxSupport.COMPONENT_TYPE);
      ajaxUF.setId(...);
      ajaxUF.setEvent("onchange");    
      ajaxUF.setReRender("thirdCombo");
      listaUF.getChildren().add(ajaxUF);

       

      "someMethodHere"

       

      public void someMethodHere(ValueChangeEvent event){
              LOG.error("someMethodHere:"+event.getNewValue()); <<< null!

      }

       

      Any help is welcome.

       

      TIA

       

      Leo K.