1
votes

Maybe someone could clear this up for me. I have an h:selectOneMenu that should do something as soon as a user selects something from the list and then rerender a link based on the results.

<h:selectOneMenu value="#{backingBean.itemSelected}"  valueChangeListener="#{backingBean.methodThatDoesStuff}" onchange="submit()" >
    <s:selectItems var="_items" value="#{backingBean.itemList}"
                    label="#{_items.Name}"  /> 
    <s:convertEntity />
</h:selectOneMenu>

My assumption was that when the user selected an item it would populate a field in the backing bean and then run the methodThatDoesStuff. But that isn't happening. backingBean.itemSelected isn't set until AFTER the method is called. I can get the event and use it directly in the method:

public void methodThatDoesStuff(ValueChangeEvent event){
        Item item = (Item)event.getNewValue();
            .... do stuff, set a flag to display link later
    }

This works.

But this leaves my aComponent set to the previous value, so the 1st time it will be null, then will change the settings based on the last itemSelected(so I'm always one behind:

public void methodThatDoesStuff(){

            Item item = this.itemSelected;  
                .... do stuff, set a flag to display link later
        }

I've tried:

<h:selectOneMenu value="#{backingBean.itemSelected}" >
<s:selectItems var="_items" value="#{backingBean.itemList}" label="#{_items.Name}"  /> 
<a:support event="onchange" ajaxSingle="true" reRender="aComponent" action="#{backingBean.methodThatDoesStuff}" />
<s:convertEntity />
</h:selectOneMenu>

But that doesn't work whether I use ValueChangeEvent or not. Is using the event object the only way to get the currently selected item? This is JSF 1.2 and Seam 2

1
I am not sure why the bound property is not getting populated before the application event phase. It could be that a validation error is occurring and thus the value never gets updated? Regardless, try implementing the BalusC Debug PhaseListener for more detailed information about what is occurring on each phase. - maple_shaft
The # is missing in action attribute. Is this a red herring or not? - BalusC
maple_shift, I'm not seeing any validation errors, and the value does get updated, AFTER the event phase. - gebuh

1 Answers

0
votes

Set attribute immediate="true" on your selectOneMenu.