0

I have the following piece of markup:

<h:selectOneMenu value="#{myBean.upperBound}">
    <f:selectItems value="#{myBean.getValues(filterItem)}" />
</h:selectOneMenu>

And the following managedBean:

public class MyBean{

    private FilterItem lowebBound;
    private FilterItem upperBound;

    public List<SelectItem> getValues(FilterItem filterItem){
         //Some stuff
    }
    //GET, SET
}

How can I initialize the property lowerBound with the value that was selected in the selectOneMenu now. I need to reinitialize that value every time it's changed.

St.Antario
  • 26,175
  • 41
  • 130
  • 318

1 Answers1

1

You need to keep the selectOneMenu and the property synched with an AJAX call.

One basic tutorial in the Oracle KB (visited 2015-04-13):

The f:ajax tag is a JavaServer Faces core tag that provides Ajax functionality to any regular UI component when used in conjunction with that component. In the following example, Ajax behavior is added to an input component by including the f:ajax core tag:

<h:inputText value="#{bean.message}">
    <f:ajax />
</h:inputText> 

Related reading:

The f:ajax listener method in h:selectOneMenu is not executed

Updating text component via selectOneMenu from inside a JSF2/Facelets subview

In your case, your component would look like this:

<h:selectOneMenu value="#{myBean.upperBound}">
    <f:selectItems value="#{myBean.getValues(filterItem)}" />
    <f:ajax listener="#{bean.listener}" />
</h:selectOneMenu>

The listener method will be called when the action is performed; you can update the lowerBound inside it.

The name of the listener method that is called when a javax.faces.event.AjaxBehaviorEvent has been broadcast for the listener.

Community
  • 1
  • 1
Mindwin Remember Monica
  • 1,469
  • 2
  • 20
  • 35