cancel
Showing results for 
Search instead for 
Did you mean: 

User tasks with custom forms: custom user inputs validation

udoderk
Champ in-the-making
Champ in-the-making
1 REPLY 1

udoderk
Champ in-the-making
Champ in-the-making
I've found the solution, as I have seen the sources of A.E.:
it is possible to register the validator on the vaadin-field in the renderer-class in Vaadin style :
textField.addValidator(new LongValidator("Value must be a long"));

package org.activiti.explorer.ui.form;
….
public class LongFormPropertyRenderer extends AbstractFormPropertyRenderer {

  public LongFormPropertyRenderer() {
    super(LongFormType.class);
  }

  @Override
  public Field getPropertyField(FormProperty formProperty) {
    final TextField textField = new TextField(getPropertyLabel(formProperty));
    textField.setRequired(formProperty.isRequired());
    textField.setEnabled(formProperty.isWritable());
    textField.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
   
    if (formProperty.getValue() != null) {
      textField.setValue(formProperty.getValue());
    }

    // Add validation of numeric value
    textField.addValidator(new LongValidator("Value must be a long"));
    textField.setImmediate(true);

    return textField;
  }
….
The validator:
package org.activiti.explorer.ui.validator;

import com.vaadin.data.validator.AbstractStringValidator;


/**
* @author Frederik Heremans
*/
public class LongValidator extends AbstractStringValidator {

  private static final long serialVersionUID = 8306001395582004472L;

  public LongValidator(String errorMessage) {
    super(errorMessage);
  }

  @Override
  protected boolean isValidString(String value) {
    try {
        Long.parseLong(value);
        return true;
    } catch (Exception e) {
        return false;
    }
  }
}
Welcome to the new Hyland Connect. Get started or submit feedback.