Lebron11
Lebron11

Reputation: 666

selectOneMenu does not change the value of the bean object

So I have the following code:

<h:inputText value = "#{listAllBookings.searchText}">
  <f:ajax listener="#{listAllBookings.printValues()}" event="keyup" render="myTable"/>
</h:inputText>             
<h:selectOneMenu value="#{listAllBookings.selectedAttr}">
  <f:selectItem itemLabel="GUEST" itemValue="GUEST"/>
  <f:selectItem itemLabel="HOTEL" itemValue="HOTEL"/>
</h:selectOneMenu>

And my printValues method:

public void printValues() {
    System.out.println("searchText:"  + searchText + " and selectedAttr: " + selectedAttr);
}

So as you can see the code above is pretty simple. The problem is that I can't change the value of the selectedAttr value. I already checked if I have the appropriate getter and setter methods. The value of the selectedAttr remains null, while the searchText value changes.

The current output looks like this:

output

Upvotes: 0

Views: 1129

Answers (2)

Selaron
Selaron

Reputation: 6184

You did not specify a component for execution with your ajax requests. So only the textfield is executed.

Add an id to the selectOneMenu and execute it:

<h:inputText value="#{listAllBookings.searchText}">
  <f:ajax listener="#{listAllBookings.printValues()}" event="keyup" render="myTable"
  execute="@this selectSomething"/>
</h:inputText>             
<h:selectOneMenu id="selectSomething" value="#{listAllBookings.selectedAttr}">
  <f:selectItem itemLabel="GUEST" itemValue="GUEST"/>
  <f:selectItem itemLabel="HOTEL" itemValue="HOTEL"/>
</h:selectOneMenu>

But you could also execute the surrounding form via execute="@form"

See also

Upvotes: 1

Ismail
Ismail

Reputation: 3042

try this:

<h:selectOneMenu value="#{listAllBookings.selectedAttr}">
<f:ajax event="change" listener="#{listAllBookings.printValues()}" />
  <f:selectItem itemLabel="GUEST" itemValue="GUEST"/>
  <f:selectItem itemLabel="HOTEL" itemValue="HOTEL"/>
</h:selectOneMenu>

Upvotes: 0

Related Questions