JSF selectOneMenu selectItem 始终为 null

发布于 2024-08-19 08:29:28 字数 1485 浏览 3 评论 0原文

我正在尝试实现一个带有支持 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期以后 2024-08-26 08:29:28

我忘记了一些事情:我添加了一个 并且我必须执行以下操作:

<h:selectOneMenu
  value="#{componentFilterBean.selectedItem}"
  immediate="true" onchange="javascript: return this.form.submit();">
  <f:selectItems value="#{componentFilterBean.projects}" />
</h:selectOneMenu>

我不明白的是,在网上的示例中,没有人这样做。

I forgot something: I added a <h:form> and I had to do the following:

<h:selectOneMenu
  value="#{componentFilterBean.selectedItem}"
  immediate="true" onchange="javascript: return this.form.submit();">
  <f:selectItems value="#{componentFilterBean.projects}" />
</h:selectOneMenu>

What I don't understand is that in the examples on the net, nobody does it that way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文