更新了代码,但没有真正的更改。
当我设置播放器时,我想用当前播放器俱乐部更新另一个选择菜单。但菜单将变为完全空白。 bean将始终返回正确的值。
从页面导航并返回将显示正确的值。在您第一次导航后,它将始终按预期工作。
<p:selectOneMenu value="#{player}"
converter="playerConverter" id="playerList">
<f:selectItem itemLabel="---" noSelectionOption="true" />
<f:selectItems value="#{servicePlayer.allPlayers}"
var="n"
itemValue="#{n}"
itemLabel="#{n.combinedName}"
itemLabelEscaped="true"/>
<p:ajax event="change" execute="@this" update="ClubMenu" actionListener="#{serviceHCP.getClubs(player)}"/>
<!-- p:ajax event="change" execute="@this" render="ClubMenu" /-->
</p:selectOneMenu>
<h:outputText value="Klubb"></h:outputText>
<p:selectOneMenu id="ClubMenu" value="#{serviceHCP.myClubList}" rendered="#{not empty serviceHCP.myClubList}">
<f:selectItems value="#{serviceHCP.getClubs(player)}" />
</p:selectOneMenu>
<h:outputText value="Serietyp"></h:outputText>
支持bean功能
public void getClubs(Player player) {
if (factory == null) {
factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
}
EntityManager em = factory.createEntityManager();
//If we have a player just return that players club
Query q;
if (player == null || player.getClub() == null)
q = em.createQuery("select t from Club t");
else {
q = em.createQuery("select t from Club t where t.id = :playerID");
q.setParameter("playerID", player.getClub().getId());
}
myClubList = q.getResultList();
for (Club aClub : myClubList) {
System.out.println("Club list info: " + aClub);
}
System.out.println("Club Size: " + myClubList.size());
em.close();
}
答案 0 :(得分:0)
您还需要处理playerList字段:
<p:ajax process="@this" update="ClubMenu" />