【发布时间】:2022-01-19 04:58:39
【问题描述】:
我正在研究 Managedbeans 和 JSF。如下所示,我的 ManagedBean 包含 JSF 获取值所需的所有要求。我已经初始化了我的下拉列表,如下所示。在 selectOneMenu 中,我选择了国家作为字符串,它将存储下拉列表选择的值,下拉列表将显示我在 Beans 中声明的列表。 不幸的是,它不是那样发生的。每次下拉呈现它都会给我一个空值。我已经花了几天时间,但无法找出确切的解决方案。我已经清理了我的服务器,构建了工作空间并更改了服务器,但没有任何效果。
** ManagedBean_list **
private List<String> listCountry;
private String country;
public void tada(){
listCountry=Arrays.asList("India", "pakisatan","America");
}
public List<String> getListCountry() {
return listCountry;
}
public void setListCountry(List<String> listCountry) {
this.listCountry = listCountry;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
JSF
<p:selectOneMenu id="country" value="#{loginBeans.country}">
<f:selectItems value="#{loginBeans.listCountry}" />
</p:selectOneMenu>
感谢您的帮助。 Empty dropdown list image enter image description here
【问题讨论】:
-
请出示
ManagedBean的完整代码。 -
排除显而易见的问题:请再次确认您已在尝试使用
<f:selectItems>标记的同一个XHTML 文件中正确声明xmlns:f="..."。有点理智的 IDE 应该已经在那里显示了一条警告线。 -
您好,感谢您的帮助。好吧,问题不在于标签库或 bean。它在列表函数的初始化中。我通过在托管 bean 类的构造函数中包含列表函数来解决它。这样当构造函数启动时。它还会生成下拉列表。
标签: jsf primefaces dropdown javabeans selectonemenu