据我所知,在 SelectOneMenu 中显示信息的正确方法是拥有一个对象列表并使用它的属性,如下所示:
<p:selectOneMenu id="player" value="">
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItems value="#{players}"
var="player"
itemLabel="#{player.name}"
itemValue="#{player.id}"/>
</p:selectOneMenu>
但是如果我没有球员名单怎么办,如果我有这样的东西怎么办?我想让它像这样工作:
//PlayerManager
public List<String> getPlayerNames() {
String[] names = new String[] {"player1", "player2"};
return Arrays.asList(names);
}
public List<String> getPlayerIds() {
String[] ids = new String[] {"1", "2"};
return Arrays.asList(ids);
}
<p:selectOneMenu id="player" value="">
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItems value="#{playerManager.playerNames}"
var="player"
itemLabel="#{playerManager.playerNames}"
itemValue="#{playerManager.playerIds}"/>
</p:selectOneMenu>