tags:

views:

603

answers:

1

Hello all,

I have information of user in bean, and I want to update this user. but my problem is: when the value of inputtext changed I want to put validation on it. and if the new value is wrong I want to reset the old value.

please can any one help me

+1  A: 

You must have ValueChangeListener property in your "InputText" tag. In your method, declared as listener you have ValueChangeEvent object wich contains 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's 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 - not to allow your ValueChangeListener override your variable set "myValue = event.getOldValue(); "

Vanger