Reputation: 666
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:
Upvotes: 0
Views: 1129
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
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