Search code examples
validationlistboxeclipse-scout

Eclipse Scout Neon ListBox: execValidateValue(..) not working


I have List box in new Neon Scout and I would like to validate value that was set.

I have implemented execValidateValue method :

  @Override
  protected Set<String> execValidateValue(final Set<String> rawValue) {

    if (rawValue.contains(CONSTANT.UNKNOWN)) {
      final Set<String> unknownSet = new HashSet<String>();
      unknownSet.add(CONSTANT.UNKNOWN);
      return super.execValidateValue(unknownSet);
    }

    return super.execValidateValue(rawValue);
  }

but it doesn't seams to have any effect. While debugging I see that inside setValue(VALUE rawValue) method updateDisplayText(validatedValue) is called with right list of strings.

Why is that? Is there something that I did wrong?

Marko


Solution

  • You are right... If a value is changed during the validation (in execValidateValue(VALUE rawValue)) as suggested by the JavaDoc, the value is stored correctly in the Scout Model but the change is not reflected in the HTML-UI.

    With the help of Samuel Renold, I have asked the team about it: The HTML-UI will be fixed to reflect the change in the UI. See bug 493778.


    Test code for the Demo Widgets Application. Change the DefaultField in the ListBoxForm.

    @Order(20)
    public class DefaultField extends AbstractListBox<Color> {
    
      @Override
      protected Class<? extends ICodeType<?, Color>> getConfiguredCodeType() {
        return ColorsCodeType.class;
      }
    
      @Override
      protected Set<Color> execValidateValue(Set<Color> rawValue) {
        System.out.println(">> execValidateValue");
        printColors(rawValue);
        if (rawValue != null && rawValue.contains(Color.RED)) {
          return super.execValidateValue(Collections.singleton(Color.RED));
        }
        return super.execValidateValue(rawValue);
      }
    
      private void printColors(Set<Color> rawValue) {
        if (rawValue != null) {
          for (Color color : rawValue) {
            System.out.print(color + ", ");
          }
          System.out.println("");
        }
        else {
          System.out.println("null");
        }
      }
    
      @Override
      protected void execChangedValue() {
        System.out.println(">> execValidateValue");
        printColors(getValue());
    
      }
    
      @Override
      protected int getConfiguredGridH() {
        return 5;
      }
    
      @Override
      protected String getConfiguredLabel() {
        return TEXTS.get("Default");
      }
    }
    

    The wrong behaviour can also be reproduced in Scout 4 (this release is end-of-life)