h:selectOneMenu和f:selectItems总是返回0

时间:2015-04-03 18:57:28

标签: jsf selectonemenu

这是我的XHTML代码:

<h:selectOneMenu id="combo" value="#{TeamsHinzufuegenBean.selectedLeagueId}">
    <f:selectItems value="#{TeamsHinzufuegenBean.leagues}"
                   var="league" itemValue="#{league.id}"
                   itemLabel="#{league.name}"/>
</h:selectOneMenu>

我的豆子:

@ManagedBean(name = "TeamsHinzufuegenBean")
@ViewScoped
public class TeamsHinzufügenBean implements Serializable{

    private static final long serialVersionUID = 1L;
    private List<League> leagues;
    private ArrayList<Team> teams = new ArrayList<Team>();
    private String teamname;
    private int selectedLeagueId=1;

    @PostConstruct
    public void init() {
        leagues = Database.getInstance().getAllLeagues();

        for(League l : leagues)
            System.out.println(l);
    }

    public List<League> getLeagues() {
        return leagues;
    }

    public void setLeagues(List<League> leagues) {
        this.leagues = leagues;
    }

    public int getSelectedLeagueId() {
        return selectedLeagueId;
    }

    public void setSelectedLeagueId(int selectedLeagueId) {
        this.selectedLeagueId = selectedLeagueId;
    }

    public ArrayList<Team> getTeams() {
        return teams;
    }

    public void setTeams(ArrayList<Team> teams) {
        this.teams = teams;
    }

    public String getTeamname() {
        return teamname;
    }

    public void setTeamname(String teamname) {
        this.teamname = teamname;
    }
}

联盟级有一个属性id,但是如果我输出selectedLeagueId的值,它总是为0。

1 个答案:

答案 0 :(得分:0)

检查getAllLeagues()是否包含具有id且已正确设置的对象