JSF selectOneMenu selectItem 始终为 null
我正在尝试实现一个带有支持 bean 的 JSF selectOneMenu 项目 选择。问题是 selectedItem 始终为 null。这里 代码是:
.xhtml:
<h:selectOneMenu
value="#{componentFilterBean.selectedItem}">
<f:selectItems value="#{componentFilterBean.projects}" />
</h:selectOneMenu>
Bean:
public class ComponentFilterBean {
String selectedItem = null;
private List<SelectItem> selectItems = null;
public String getSelectedItem() {
System.out.println("getSelectedItem = " + selectedItem);
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
System.out.println("setSelectedItem = " + selectedItem);
}
public List<SelectItem> getProjects() {
if (selectItems == null) {
selectItems = new ArrayList<SelectItem>();
selectItems.add(new SelectItem("Project1", "Project1"));
selectItems.add(new SelectItem("Project2", "Project2"));
selectItems.add(new SelectItem("Project3", "Project3"));
}
return selectItems;
}
}
faces-config.xml:
<managed-bean>
<managed-bean-name>componentFilterBean</managed-bean-name>
<managed-bean-class>test.ComponentFilterBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
我正在使用 sun 实现(版本 1.2)。问题出现在 Jetty 6 上 和WebSphere 6.1。
有人能帮我解决这个问题吗?
基督教
I'm trying to implement a JSF selectOneMenu item with a backing bean holding
the selection. The problem is that the selectedItem is always null. Here
is the code:
.xhtml:
<h:selectOneMenu
value="#{componentFilterBean.selectedItem}">
<f:selectItems value="#{componentFilterBean.projects}" />
</h:selectOneMenu>
Bean:
public class ComponentFilterBean {
String selectedItem = null;
private List<SelectItem> selectItems = null;
public String getSelectedItem() {
System.out.println("getSelectedItem = " + selectedItem);
return selectedItem;
}
public void setSelectedItem(String selectedItem) {
this.selectedItem = selectedItem;
System.out.println("setSelectedItem = " + selectedItem);
}
public List<SelectItem> getProjects() {
if (selectItems == null) {
selectItems = new ArrayList<SelectItem>();
selectItems.add(new SelectItem("Project1", "Project1"));
selectItems.add(new SelectItem("Project2", "Project2"));
selectItems.add(new SelectItem("Project3", "Project3"));
}
return selectItems;
}
}
faces-config.xml:
<managed-bean>
<managed-bean-name>componentFilterBean</managed-bean-name>
<managed-bean-class>test.ComponentFilterBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
I am using the sun implementation (version 1.2). The problem appears on Jetty 6
and WebSphere 6.1.
Can anybody help me with that problem?
Christian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我忘记了一些事情:我添加了一个
并且我必须执行以下操作:我不明白的是,在网上的示例中,没有人这样做。
I forgot something: I added a
<h:form>
and I had to do the following:What I don't understand is that in the examples on the net, nobody does it that way.