Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » execChangedValue not firing if an invalid value is reverted back to the previous value
execChangedValue not firing if an invalid value is reverted back to the previous value [message #1220946] Mon, 16 December 2013 10:09 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 341
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Background for this bug
In our application we have forms where there are both validation rules for each single field (covered in their execValidateValue() methods) and some multi-field-validation rules. Those rules are checked in one common method validateFields() which is called from each fields execValueChanged() method.

Let's assume the following case to illustrate our problem

  • We have two fields: An integer field and a checkbox
  • The integer field has an execValidateValue() method which validates the raw value of the IntField (say any value > 4000 throws a VetoException)
  • In the execChangedValue() methods of both fields we call validateFields() to do the multi-field validations (say if the checkbox is set and the int field contains an even value, its error status is set; if the checkbox is not set and the int field contains an odd value, its error status is set).


The Problem

  • Let's assume that the checkbox is set
  • The user now enters a new value into the int field: 444
  • execValidateValue() on the IntField accepts the value (it's below 4000)
  • execChangedValue() calls our validation method validateFields() which detects an even value and sets the error status on the IntField.
    The IntField now shows an error status
  • Now, the user enters a new value into the int field: 4444
    execValidateValue() on the IntField throws a VetoException, the IntField now shows the new error status, execChangedValue() is never called
  • Now, the user corrects his mistake, restoring the old value: 444
  • execValidateValue() on the IntField accepts the value (it's below 4000)

As AbstractValueField.setValue() contains the following lines:
if (getErrorStatus() instanceof ValidationFailedStatus) {
clearErrorStatus();
}
and
if (getErrorStatus() instanceof ParsingFailedStatus) {
clearErrorStatus();
}
These lines clear the error status of the IntField. Our initial condition still applies: The checkbox is set and an even value is in the IntField, our validateFields() method would set the error status again. However, execChangedValue() is never called on the IntField, as the oldValue and the newValue are both 444 (the vetoed value 4444 was never propagated far enough).

Is there any way of setting up a multi-field-validation routine that will work correctly in the described case?
Re: execChangedValue not firing if an invalid value is reverted back to the previous value [message #1220956 is a reply to message #1220946] Mon, 16 December 2013 11:00 Go to previous messageGo to next message
Fabien Ropraz is currently offline Fabien RoprazFriend
Messages: 1
Registered: December 2013
Junior Member
Further precision:

The implementation in AbstractValueField.setValue() precisely prevents the property change to be fired as the value is the same as the previous one, which is in this case quite inconvenient and undesired:

oldValue = getValue();
boolean changed = propertySupport.setPropertyNoFire(PROP_VALUE, validatedValue);
if (changed) {
propertySupport.firePropertyChange(PROP_VALUE, oldValue, validatedValue);
...
}
Re: execChangedValue not firing if an invalid value is reverted back to the previous value [message #1221870 is a reply to message #1220956] Wed, 18 December 2013 15:33 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 796
Registered: October 2011
Senior Member
I am not sure to understand why is going wrong in your case:

When the user enters "4444" the value is never changed.
As you say, there is a VetoException in execValidateValue(), meaning that the value is not changed in the Scout Model.

In the UI we keep the text "4444" and an error marker to give the user a chance to correct its mistake.
At this point:
- The value is not changed in the Scout Model.
- This is why execChangedValue is not called.
- if you call getValue() on your field, it will return 444 (the previous valid value).

If the user corrects the error back the previous value, this is OK but the value in the scout model won't change (it was 444 and is again 444).


I do not know your use case...

Sometime I had to bypass the Validation concept of Eclipse Scout (meaning accepting a value that is technically correct, but not valid from a business point of view. When your value got accepted in ValidateValue, you can set or remove the errorStatus in execChangedValue depending on your own logic. Be aware that in this case, all the values will be valid from the Scout-Validation Framework point of view. This means that you need to be extra careful, when you import/export data and when you handle the form lifecycle.)

I hope its helps.

Re: execChangedValue not firing if an invalid value is reverted back to the previous value [message #1221874 is a reply to message #1221870] Wed, 18 December 2013 15:42 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 341
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jérémie

The problem is that correcting the error (from 4444 back to 444) clears the errorStatus that we have set using our logic in execChangedValue() for 444. The issue is that we have no way to re-apply our own logic in this case.
Re: execChangedValue not firing if an invalid value is reverted back to the previous value [message #1221984 is a reply to message #1221874] Thu, 19 December 2013 08:05 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 796
Registered: October 2011
Senior Member
In my opinion, you cannot mix error handling in execValidateValue and execChangedValue. This is my personal opinion. I see it as one of the limitation of our current validation framework. Maybe other people will see it an other way.
Re: execChangedValue not firing if an invalid value is reverted back to the previous value [message #1227998 is a reply to message #1221984] Mon, 06 January 2014 07:05 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 341
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jeremie, do you see any way to work around that limitation? How would you propose to do "multi field validation"?
Re: execChangedValue not firing if an invalid value is reverted back to the previous value [message #1229002 is a reply to message #1221984] Wed, 08 January 2014 14:22 Go to previous messageGo to next message
Ken Lee is currently offline Ken LeeFriend
Messages: 97
Registered: March 2012
Member
Jeremie Bresson wrote on Thu, 19 December 2013 03:05
In my opinion, you cannot mix error handling in execValidateValue and execChangedValue.


I suppose that Jérémie is right. The Javadoc of execValidateValue says:

  /**
   * WHILE (not after) a new value is validating (that means the new value has
   * not yet been set), this methode is called.<br>
   * Check the new proposed value and either make it valid by returning this or
   * another valid value or reject by throwing a {@link VetoException}, it will
   * then appear red in the gui.
   * 
   * @return the validated value or throws an exception
   */


whereas execChangedValue says:

 /**
   * AFTER a new valid value was stored (that means the value is valid), this
   * method is called and can be used to broadcast this change to other fields
   * by for example calling {@link IValueField#setValue(Object)} on another
   * field...


This means that in your case the value is not valid and therefore the method execChangedValue will not get fired.

Urs Beeli wrote on Mon, 06 January 2014 02:05
Jeremie, do you see any way to work around that limitation? How would you propose to do "multi field validation"?


In one of our Scout project, we also have to do multiple field validation. Similar to your approach we have a validator that is implemented as a service however. The service is located in the shared package so that it could used in the client without having to call a server service.
In the execChangedValue method the current values of the form is exported into a formdata and then passed to the validator service.
After validation, the validated formdata is imported again. Be aware to set the flag valueChangeTriggersEnabled to false when calling the method importFormData. Otherwise, the validated values could trigger execChangedValue again Smile
With this approach, we don't use the execValidateValue method at all.

Re: execChangedValue not firing if an invalid value is reverted back to the previous value [message #1229311 is a reply to message #1229002] Thu, 09 January 2014 07:05 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 341
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Ken, thanks for your suggestion on validation. I'll discuss it with Fabien to see if this approach would be feasible for us as well.
Previous Topic:Adding TAB boxes programmatically dynamically via a button
Next Topic:Trying to get scout-rt and scout-sdk to build...
Goto Forum:
  


Current Time: Thu Nov 27 01:54:17 GMT 2014

Powered by FUDForum. Page generated in 0.31436 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software