<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<h3>Search</h3>
<p:selectOneButton id="searchType" value="#{bean.searchType}">
<f:selectItem itemLabel="1" itemValue="1" />
<f:selectItem itemLabel="2" itemValue="2" />
<f:selectItem itemLabel="3" itemValue="3" />
<p:ajax event="change" update="search selected" />
</p:selectOneButton>
<p:autoComplete id="search" forceSelection="true" dropdown="true" value="#{bean.selectedSearch}" completeMethod="#{bean.search}">
</p:autoComplete>
<p:spacer />
<h:outputText value="Selected:" />
<h:outputText id="selected" value="#{bean.searchType}" style="font-weight: bold" />
</h:panelGrid>
</h:form>
我想根据按下 selectOneButton 来更改建议列表,但 autoComplete 仅显示加载页面时选择的建议列表。< / p>
bean completeMethod
private int searchType;
private ArrayList<String> auditoryNumberList;
private ArrayList<String> lectureNameList;
private ArrayList<String> groupNameList;
private String selectedSearch;
public ArrayList<String> search(String q) throws SQLException {
switch (searchType) {
case 1:
if (groupNameList == null) {
groupNameList = model.getGroupNameList();
return model.search(groupNameList, q);
} else {
return model.search(groupNameList, q);
}
case 2:
if (lectureNameList == null) {
lectureNameList = model.getLectureNameList();
return model.search(lectureNameList, q);
} else {
return model.search(lectureNameList, q);
}
case 3:
if (auditoryNumberList == null) {
auditoryNumberList = model.getAuditoryNumberList();
return model.search(auditoryNumberList, q);
} else {
return model.search(auditoryNumberList, q);
}
default:
return null;
}
}