Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get updated model values in a valueChangeListener method?

I am stuck with an issue on valueChangeListener. I am using JSF 1.2 on Weblogic 6.0.

I have a page, where on top of the page there are 2 radio buttons with name as Name1 and Name2. When Name1 is clicked, the Name1 details(there are about 30 fields) is displayed below the radio buttons and when Name2 is clicked, Name2 details is displayed. Now the user can updated the clicked named details. e.g. the user clicks on Name1 and changes the address field and then clicks on Name2 and changes the age of Name2. When the user clicks back Name1, the address should be shown updated with the new value and again when the user clicks on Name2, the age should be updated.

I have used valueChangeListener to tackle it because I need the old and new value of the changed event. The problem is, as the valueChangeListener is invoked at the end of the VALIDATION phase, I am not getting the updated address of the Name1 field in the valueChangeListener method. Can someone help me out to get any workaround ?

like image 513
Suman Avatar asked Jan 05 '13 11:01

Suman


1 Answers

as the valueChangeListener is invoked at the end of the VALIDATION phase, I am not getting the updated address of the Name1 field in the valueChangeListener method

Queue the event to the INVOKE_ACTION phase so that it acts like as an action(listener) method.

public void valueChangeListenerMethod(ValueChangeEvent event) {
    if (event.getPhaseId() != PhaseId.INVOKE_APPLICATION) {
        event.setPhaseId(PhaseId.INVOKE_APPLICATION);
        event.queue();
        return;
    }

    // Do your original job here. 
    // It will only be entered when current phase ID is INVOKE_APPLICATION.
}

As INVOKE_ACTION phase runs after UPDATE_MODEL_VALUES, the updated model values will be just available "the usual way".

like image 104
BalusC Avatar answered Nov 12 '22 19:11

BalusC