absolution_brazil wrote:
Hi all,
I'm developing an application using JSF with ajax4jsf. On my page I've an input text that I type some string an then I click in a button. This button triggers an a4j action that's used to load a selectOneMenu with the data retrieved based on that string. I put an empty string as my first value into the selectOneMenu. The problem is if I select one of the elements of my selectOneMenu and then I make another query (filling the input text and clicking on the button) the selectOneMenu is loaded again with the new values but that one chosed by my first query keeps selected.
I want to know how I could set the default value of the selectOneMenu. I already tried using the value attribute of the h:selectOneMenu. I clear that list every time I'm about to fill it.
I don't know what to do to solve this problem anymore.
Someone could point me where could be the problem?!
Yes, you can set the initial value on the select one. I'm assuming that you have something like this:
<h:panelGrid id="currentPanel" columns="1">
<h:selectOneMenu id="menuId" value="#{managedBean.formValue}">
<f:selectItem itemValue="" itemLabel="Select a value ..."/>
<f:selectItems value="#{myBean.selectList}"/>
<a4j:support event="onchange" action="#{managedBean.handleSelection}" reRender="currentPanel"/>
</h:selectOneMenu>
</h:panelGrid>
There are two likely problems. One is that the handleSelection() method on the managed bean not not have reset the formValue variable, like the method does below:
String handleSelection() {
// Do some stuff
...
// Reset the selection
setFormValue("");
return "handleSelectionSucceeded";
}
Another likely cause is that you didn't rerender the panel that contains the selectOneMenu. If neither of these are causing the problem, you might have a validation error somewhere that is being eaten. I would slap an <h:messages> in an ajaxRendered="true" a4j outputPanel to see if that's the case.