I need to update selection list based on value in input field. Because of the update delay I do not want to update the selection list if it already has correct options. Shouldn't be too difficult I thought and tried this:
<p:inputText value="#{bean.inputValue}">
<p:ajax update="#{bean.updateElement}">
</p:inputText> /
<h:selectOneMenu id="so" value="#{bean.soValue}">
<f:selectItem />
<f:selectItems value="#{bean.options}" var="option" itemLabel="#{option}"/>
</h:selectOneMenu>
But it does not work because bean.updateElement
does not get called when value in input field changes.
OK I need to use p:remoteCommand
then. I was sure it would work with this:
<p:ajax oncomplete="updateSelect()"/>
..
<p:remoteCommand name="updateSelect" update="dt:so" oncomplete="alert('done')" />
The fields are in a p:dataTable id="dt"
row. I get the alert but bean.options
is still not called. If I change it to update="dt"
it works and the whole datatable is updated but that's not what I want. I also tried with so
form:dt:so
and :form:dt:so
.
Then I tried a couple of more options I could find:
RequestContext.getCurrentInstance().update("dt:so");
..
FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add("dt:so");
but nothing happens. Tried also without dt:
.
Edit:
I got one step closer this way:
<p:ajax update="@this #{bean.updateElement}"/>
Now bean.updateElement
gets called every time I change input field value but the select component does not update until the next time I change the input field value. bean.updateElement
returns "so" or "" depending on input field value.
Edit 2:
Using this the selected option stays when input field is modified:
<f:ajax execute="so" render="so" partialSubmit="true" />
I also tried with <p:ajax process="so" update="so />
but the options are not any more updated. Keeping the selected option was one of my goals so this is good but could be better still.
How can I make this very simple thing work? My setup is this:
- Tomcat 7.0.53
- Mojarra 2.2.7
- primefaces-5.0.jar
- JRE 1.8.0_05