リスト (stationaryList) を再作成するにはどうすればよいですか? 私のコードで何が問題になっていますか? 値 = 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);
}