0

i have two oneSelectMenu loaded with default values based on login Details,then second selectonemenu should load value based on first selectonemenu's onchangeEvent menu.i tried to clear the default value before onchange event but the value remains and doesn't work with onchange event.

<h:selectOneMenu id="blS" value="#{BoardAction.serviceAreaId}" >
<f:ajax event="valueChange" render="blSearchFacilityInput" listener="#{BoardAction.svaValueChangeEvent}"/> 
 <f:selectItems value="#{BoardAction.serviceAreaList}" var="c"  itemLabel="#{c.svaCode}" itemValue="#{c.id}"/> </h:selectOneMenu>

 <h:selectOneMenu id="blSearchFacilityInput" value="#{BoardAction.facilityId}">                                                         <f:ajax event="valueChange" render="blSearchSectorInput" listener="#{BoardAction.facValueChangeEvent}"/> 
<f:selectItems value="#{BoardAction.svaFaciltyList}" var="c" itemLabel="#{c.facCode}" itemValue="#{c.id}"/></h:selectOneMenu>

ActionBean :

private List<FacilityEBean> svaFaciltyList=null;

public List<FacilityEBean> getSvaFaciltyList() {
svaFaciltyList = facilityBusServ.getFacilityListBySVAId(session.getLoginUser());
return svaFaciltyList;
    }

public List<FacilityEBean> svaValueChangeEvent(){
        if(svaFaciltyList!=null){
            svaFaciltyList.clear();
            svaFaciltyList=null;
        }

  svaFaciltyList = facilityBusServ.getFacilityList(Integer.parseInt(serviceAreaId));
  return svaFaciltyList;

    }
Bernad Ali
  • 1,699
  • 6
  • 23
  • 29

1 Answers1

1

Your code logic flow is wrong. You seem to expect that input components are in some way directly bound to properties and that the ajax action listener methods can return (changed) property values. This is thus actually not true.

For example, the EL expression #{BoardAction.serviceAreaList} actually invokes the getter method for the property. In your particular case, the getter method fills the list with the results from the DB everytime. So whatever you're setting in the ajax listener method is overridden everytime by the business logic in the getter method.

Those getter methods should not contain business logic at all. You need to rewrite your code as follows:

private List<FacilityEBean> svaFaciltyList;

@PostConstruct
public void init() {
    svaFaciltyList = facilityBusServ.getFacilityListBySVAId(session.getLoginUser());
}

public void svaValueChangeEvent() {
    svaFaciltyList = facilityBusServ.getFacilityList(Integer.parseInt(serviceAreaId));
}

public List<FacilityEBean> getSvaFaciltyList() {
    return svaFaciltyList;
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555