Value Field / Error handling / invalid value [message #1403082] |
Mon, 21 July 2014 09:00 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
Regarding value fields, eclipse scout follows those paradigms:
* If the user enters a value that is wrong, the UI should stay as it is, letting a chance for the user to correct his error.
* The scout model should only contain valid value. Meaning that a value that is not valid, will not be set into the model.
This works well in most of the cases, but this might be something we need to improve. Here the 2 problem I see with the current approach:
Let consider an Integer field with:
- Min value set to 5
- Max value set to 10
1/ Be aware of it when you use getValue()
To get the value contained in a field you call getValue() on the field.
You need to be aware that if the user makes an invalid input, getValue() will return the previous valid value.
Example sequence 1:
//user enters a '7'
getIntField().getValue(); //returns 7
getIntField().getErrorStatus(); //returns null
//user enters another '7' (text in the integer field is now 77)
getIntField().getValue(); //returns 7 (previous valid value)
getIntField().getErrorStatus(); //returns ParsingFailedStatus[ERROR code=0 The value is too large; must be between 5 and 10.]
//user enters 'DEL' (text in the integer field is now 7)
getIntField().getValue(); //returns 7
getIntField().getErrorStatus(); //returns null
Example sequence 2:
//user enters a '3'
getIntField().getValue(); //returns null (because no previous valid value)
getIntField().getErrorStatus(); //returns ParsingFailedStatus[ERROR code=0 The value is too small; must be between 5 and 10. ]
Depending on your use case you might need to check the error status before reading the value:
Integer value;
if(getIntField().getErrorStatus() == null) {
value = getIntField().getValue();
} else {
value = null;
}
2/ Invalid value set programmatically
Because the framework work with the assumption that only valid values are set in the scout model layer, the framework is acting wired when a wrong value is set:
Example sequence 3:
//getIntField().setValue(14)
getIntField().getValue(); //returns null (because no previous valid value)
getIntField().getErrorStatus(); //returns ParsingFailedStatus[ERROR code=0 The value is too large; must be between 5 and 10. ]
The UI will looks like this:
The effect is exactly the same if you import a formData with a value set to 14 in the formData.
This is really wired because the user has no idea what is wrong in this field.
This has been reported in bug 419693.
3/ Related forum post:
Urs Beeli is discussing the same problem: ExecChangedValue not firing if an invalid value is reverted back to the previous value
The problem is described and discussed here.
If you are aware of other discussions (forum, bugzilla, offline...) feel free to discuss it in this forum thread.
New API needed?
I really no not know what a generic solution could be. In my opinion the API to get/set Value and handle errors (technical exception like parsing error or business exception like min/max values) is sometimes limited. If we go in this direction we also need to consider:
- SmartField.execValidateValue cannot be used
- Update the value of a field during its own execChangedValue() event.
- Controlling if execChangedValue() is called or not.
Such a refactoring would be a big API change. We need to be sure of it, before starting something in this direction.
Any though on this?
My current problem
For the moment I am looking for a workaround for the problem described in Bug 419693. I need to be able to import invalid values in value fields. In this project I have a lot of server side error validations. I want to have the values imported into the form as they are provided by the backend, without error markers, even if an user could not enter the same value in the UI.
.
-
Attachment: ui.png
(Size: 4.10KB, Downloaded 663 times)
|
|
|
|
Re: Value Field / Error handling / invalid value [message #1403099 is a reply to message #1403092] |
Mon, 21 July 2014 11:33 |
Jeremie Bresson Messages: 1252 Registered: October 2011 |
Senior Member |
|
|
Urs Beeli wrote on Mon, 21 July 2014 12:58Changing the value back to the previous value in execChangedValue() is not possible because at that point in time the flag for "valueIsChanging" is still true. The only way I can think of solving my problem is to run a job to set the value back to the previous value a few hundred milliseconds later, when the field status is no longer "changing".
Same in my current project: to reset a value in a smart field to a previous value (something like "rejecting the value change"), I had to schedule a ClientSyncJob in execChangedValue(). Similar to what I have described here.
.
[Updated on: Mon, 21 July 2014 12:59] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04967 seconds