English 中文(简体)
JSF selectOneMenu selectItem always null
原标题:

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

最佳回答

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.

问题回答

暂无回答




相关问题
JSF a4j:support with h:selectManyCheckbox

I m having trouble with a JSF selectManyCheckbox and A4J support. The purpose is to run some action when a checkbox is selected. This works perfectly in Firefox. Yet, when testing in any IE (ie6 / ie7 ...

Mojarra for JSF Encoding

Can anyone teach me how to use mojarra to encode my JSF files. I downloaded mojarra and expected some kind of jar but what i had downloaded was a folder of files i don t know what to do with

如何拦截要求终止?

在共同基金中,如果用户要求终止,就需要采取一些行动。 我需要某种拦截器,但我不知道如何这样做。 我需要帮助。 增 编

ICEFaces inputFile getting the file content without upload

Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading ...

Weird behaviour of h:commandLink action (MethodExpression)

I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

How to correctly use ResultSet with h:dataTable

The problem is, that after displaying the ResultSet with <h:dataTable>, the connection is left open. If I close it, it closes the ResultSet too. I m thinking about copying the ResultSet data ...

热门标签