Search code examples
javaoracle-adfmanaged-bean

hide show componant in adf


I have 3 SelectOneChoice which are not to datacontrol, depending on the value of first SelectOneChoice the other 2 SelectOneChoice should show and hide. I used manged bean and i used valueChangeListener for the first SelectOneChoice to hide and show the other 2 SelectOneChoice based on the selection, and partial in the other 2 SelectOneChoice but it did not work

here is the first SelectOneChoice

<af:selectOneChoice label="acnt type"  id="soc10"  valueChangeListener="#{backingBeanScope.JasperBean.hideShowAccounts}"
              autoSubmit="true" required="true" contentStyle="width:118px">
           <af:selectItem label="Cultural Division Accounts" value="CA" id="si12"/>
           <af:selectItem label="Students Accounts" value="SA" id="si13"/>
</af:selectOneChoice>

here are the other 2 SelectOneChoice

 <af:selectOneChoice label="bb"
    valueChangeListener="#{backingBeanScope.JasperBean.storeAccount}"
        id="soc11" autoSubmit="true" partialTriggers="soc10">
      <af:selectItem label="Select Account" value="-1" id="si220"/>
      <f:selectItems value="#{backingBeanScope.JasperBean.accounts}" id="si1"/>
 </af:selectOneChoice>

 <af:selectOneChoice label="aa"
             valueChangeListener="#{backingBeanScope.JasperBean.storeAccount}"
                id="soc12" autoSubmit="true" 
   partialTriggers="soc10"
            rendered="#{backingBeanScope.JasperBean.saShown}">
       <af:selectItem label="Select Account" value="-1" id="si221"/>
       <f:selectItems value="#{backingBeanScope.JasperBean.studentAccounts}"  id="si121"/>
</af:selectOneChoice>

here is the managed bean code.

    public void hideShowAccounts(ValueChangeEvent valueChangeEvent) {

    if(valueChangeEvent.getNewValue().toString().equals("CA"))
    {            

        ddlCAaccounts.setRendered(true);
        ddlSAaccounts.setRendered(false);
    }
    else if(valueChangeEvent.getNewValue().toString().equals("SA"))
    {

        ddlCAaccounts.setRendered(false);
        ddlSAaccounts.setRendered(true);
    }

}

if it can be done using javascript also tell me how, not necessary that is done in managed bean


Solution

  • There is a two step solution for this:

    1. Add valuePassThru="true" for selectOneChoice component.

    2. Add valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance()); as first line in you value change listener code.

    For details please refer to https://community.oracle.com/people/2623233/blog/2015/02/05/valuechangeevent-does-not-fire-for-afselectonechoice-in-adf