0

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

Lebron11
  • 656
  • 7
  • 18
  • Possible duplicate of [Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes](https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes) – Jasper de Vries Mar 28 '19 at 11:16

2 Answers2

1

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

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Selaron
  • 6,105
  • 4
  • 31
  • 39
0

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>
Ismail
  • 2,322
  • 1
  • 12
  • 26