0

我正在尝试制作一个动态菜单,以便在第一个选择器中选择某些内容时,根据第一个选择器中的选择从数据库中填充第二个。这是.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 都是新手,所以如果我做错了,请随时将我拆散。谢谢你的帮助!

4

1 回答 1

1

@ManagedBean的行为类似于带有@Stateless注释的 EJB。删除它,而是将 bean 的范围设置为@ViewScoped

@ManagedBean(name = "selectorBean")
@ViewScoped
public class SelectorBean implements Serializable{
    //your implementation...
}

此外,请确保遵循JavaBean 命名约定。我已将您的班级名称更改为以大写字母开头。

于 2013-06-27T14:57:45.557 回答