Iceface: reset old values ​​on update

I have a user information in a bean and I want to update this user. but my problem is that when the value of the input text changes, I want to put a validation on it. and if the new value is not correct, I want to reset the old value.

please can someone help me

+1


a source to share


1 answer


You should have a ValueChangeListener property in the "InputText" tag. In your method declared as a listener, you have a ValueChangeEvent object that contains the old value. You can do something like this:

public void myValChanged(ValueChangeEvent event) {
 try {
   validate(event.getNewValue());
   myValue = event.getNewValue();
 } catch (Exception ex) {
    /*
    Listeners are called before update model values in the request lifecycle so any changes you make in that phase are overwritten by the actual values in the page.
    By changing the event phase to UPDATE_MODEL_VALUES or INVOKE_APPLICATION your changes will overwrite those currently set in the page, which is what you need.
     */
            myValue = event.getOldValue();
    if (!event.getPhaseId().equals(PhaseId.INVOKE_APPLICATION)) {
        event.setPhaseId(PhaseId.INVOKE_APPLICATION);
        event.queue();
        return;
    }       
 }

}

      



The idea with PhaseId operations is to prevent your ValueChangeListener from overriding your set variable " myValue = event.getOldValue();

"

+2


a source







All Articles