我正在尝试制作一个动态菜单,以便在第一个选择器中选择某些内容时,根据第一个选择器中的选择从数据库中填充第二个。这是.xhtml:
<f:view>
<h:form>
<h:selectOneMenu id="seasonSelector" value ="#{selector_bean.season}">
<f:ajax event="valueChange" listener="#{selector_bean.genEvents}"
execute="seasonSelector" render="eventSelector" />
<f:selectItems value ="#{selector_bean.seasons}" var ="s"
itemLabel="#{s.getRange()}"
itemValue="#{s}"></f:selectItems>
</h:selectOneMenu>
<h:selectOneMenu id="eventSelector">
<f:selectItems value ="#{selector_bean.events}" var ="e"
itemLabel="#{e.event_Name}"
itemValue="#{e}"></f:selectItems>
</h:selectOneMenu>
</h:form>
</f:view>
这是豆:
@ManagedBean(name = "selector_bean")
@Stateless
public class selector_bean implements Serializable{
@EJB
SeasonFacade sf;
@EJB
EventFacade ef;
@EJB
WrestlerFacade wf;
private Season season;
private Event event;
private List<Event> events;
private Match match;
private Wrestler wrestler;
public List<Season> getSeasons(){
return sf.findAll();
}
public void genEvents(AjaxBehaviorEvent event){
events = (ef.findBySeason(season));
}
// setters and getters after this
当我更改第一个 selectOneMenu 的值时,会出现一个带有以下消息的弹出框:
httpError: There was an error communicating with the server, status: 404
我对 JSF 和 AJAX 都是新手,所以如果我做错了,请随时将我拆散。谢谢你的帮助!