如何重新填充我的列表 (stationaryList) ?我的代码有什么问题?如果我选择 value = CDL 或 MEL 或 NEF,我的列表中没有任何变化。谢谢。
<h:form id="frmCreateNewStationary">
<ui:param name="s" value="#{myController.selected}"/>
<h:panelGrid columns="2">
<h:outputLabel value="Type" for="idType" />
<h:selectOneMenu id="idType" value="#{s.stationaryid.type}">
<f:selectItem itemLabel="Select ..." noSelectionOption="true" />
<f:selectItem itemLabel="CDL" itemValue="CDL" />
<f:selectItem itemLabel="MEL" itemValue="MEL" />
<f:selectItem itemLabel="NEF" itemValue="NEF" />
<f:ajax event="change" listener="#{myController.changeStationaryCodeList}" render="idCode" execute="@this" />
</h:selectOneMenu>
<h:outputLabel value="Code" for="idCode" />
<h:selectOneMenu id="idCode" value="#{s.stationaryid.code}">
<f:selectItem itemLabel="Select ..." noSelectionOption="true" />
<f:selectItems value="#{myController.stationaryList}" />
</h:selectOneMenu>
</h:panelGrid>
</h:form>
爪哇
private List<Stationary> stationaryList = null;
public List<Stationary> getStationaryList() {
stationaryList = getCode();
return stationaryList;
}
public void setStationaryList(List<Stationary> stationaryList) {
this.stationaryList = stationaryList;
}
...
public List<Stationary> getCode() {
//"Stationary.ccc", query = "SELECT s.code FROM Stationary s"),
EntityManager emf = facade.getEntityManager();
Query query = emf.createNamedQuery("Stationary.ccc");
return query.getResultList();
}
...
public List<Stationary> getStationaryCodeItems(String type) {
//"Stationary.code", query = "SELECT s.code FROM Stationary s WHERE s.type = :type"),
EntityManager emf = facade.getEntityManager();
Query query = emf.createNamedQuery("Stationary.code");
query.setParameter("type", type);
return query.getResultList();
}
AjaxBehaviorEvent 看起来像这样:
public void changeStationaryCodeList(AjaxBehaviorEvent ev) {
stationaryList.clear();
String type = (String) ((UIInput) ev.getComponent()).getValue();
System.out.println("Test__changeStationaryCodeList -- state == " + type);
stationaryList = getStationaryCodeItems(type);
//setStationaryList(stationaryList);
}