0

我有两个 oneSelectMenu 根据登录详细信息加载了默认值,然后第二个 selectonemenu 应该根据第一个 selectonemenu 的 onchangeEvent 菜单加载值。我尝试在 onchange 事件之前清除默认值,但该值仍然存在并且不适用于 onchange 事件。

<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>

动作豆:

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;

    }
4

1 回答 1

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;
}
于 2012-09-01T21:18:48.803 回答