Problem with selectOneMenu JSF.

View: New views
3 Messages — Rating Filter:   Alert me  

Problem with selectOneMenu JSF.

by absolution_brazil :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


 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?!

Re: Problem with selectOneMenu JSF.

by kordzik :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm getting similar problem. In my case, the value of a t:selectOneMenu control decides about some input boxes being / not being rendered on the page. One of the a4j action listeners resets this t:selectOneMenu to a default value. This value is set in the application phase, because the proper input boxes are rendered. However after the a4j request, during which the action listener was called, the displayed value of  t:selectOneMenu does not change (is not updated from the bean). as a result, the rendered text input controls do not correlate with the value displayed in the drop down box like they should. The t:selectOneMenu is in the area which is specified in the reRender property of pertinent a4j:support tag. Is it a bug, is there a walkaround for that?

Any comments are welcome.


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?!

Re: Problem with selectOneMenu JSF.

by BernieM :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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.