Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Value Field / Error handling / invalid value
Value Field / Error handling / invalid value [message #1403082] Mon, 21 July 2014 09:00 Go to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
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:
index.php/fa/18600/0/

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 #1403092 is a reply to message #1403082] Mon, 21 July 2014 10:58 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thank you for summarising this issue Jérémie. Just last week I ran into a situation where I do not want to let the user choose an "empty" (null) value in a smartfield. There is currently no easy way to achieve this. Setting the field to mandatory does not stop the user from choosing a null value, it just marks the field as "erronous". Checking for this in the execValidateValue() method is not possible, because that is final in AbstractSmartField. Changing 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".
Re: Value Field / Error handling / invalid value [message #1403099 is a reply to message #1403092] Mon, 21 July 2014 11:33 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Urs Beeli wrote on Mon, 21 July 2014 12:58
Changing 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

Re: Value Field / Error handling / invalid value [message #1403119 is a reply to message #1403082] Mon, 21 July 2014 13:00 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Jeremie Bresson wrote on Mon, 21 July 2014 11:00
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.


I need to by-pass the field validation when I am importing values from the FormData.
For the moment my solution looks like this:

public abstract class AbstractSdbxIntegerField extends AbstractIntegerField {
  private boolean m_isFormDataImporting;

  @Override
  public void importFormFieldData(AbstractFormFieldData source, boolean valueChangeTriggersEnabled) {
    try {
      m_isFormDataImporting = true;
      super.importFormFieldData(source, valueChangeTriggersEnabled);
    }
    finally {
      m_isFormDataImporting = false;
    }
  }

  @Override
  protected Integer validateValueInternal(Integer rawValue) throws ProcessingException {
    if (m_isFormDataImporting) {
      return super.validateValueInternal(rawValue);
    }
    return rawValue;
  }
}


Where AbstractSdbxIntegerField is the integer field template I use in everywhere my application.

I need to add this in all value fields I use:
* DateTime field
* Date field
* BigDecimal field
* Integer field
* Long field
* String field
* Boolean field
* SmartField field

I someone has a better solution...

.
Previous Topic:Page templates
Next Topic:Using icons in a table
Goto Forum:
  


Current Time: Fri Mar 29 15:42:45 GMT 2024

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

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

Back to the top