com.vaadin.ui.Field.validate()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(2.8k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中com.vaadin.ui.Field.validate()方法的一些代码示例,展示了Field.validate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Field.validate()方法的具体详情如下:
包路径:com.vaadin.ui.Field
类名称:Field
方法名:validate

Field.validate介绍

暂无

代码示例

代码示例来源:origin: korpling/ANNIS

@Override
public void validate() throws InvalidValueException
{
 field.validate();
}

代码示例来源:origin: org.opennms.features/jmxconfiggenerator.webui

@Override
public void validate() throws InvalidValueException {
  super.validate();
  InvalidValueException validationException = null;
  //validators must be invoked manually
  for (Field<?> tf : fieldsToValidate.values()) {
    try {
      tf.validate();
    } catch (InvalidValueException ex) {
      validationException = ex;
    }
  }
  if (validationException != null) throw validationException;
}

代码示例来源:origin: org.aperteworkflow/gui-commons

@Override
  public void buttonClick(Button.ClickEvent event) {
    Map<Field, String> messages = new LinkedHashMap<Field, String>();
    for (Object propertyId : form.getItemPropertyIds()) {
      Field field = form.getField(propertyId);
      try {
        field.validate();
      }
      catch (Validator.InvalidValueException e) {
        messages.put(field, e.getMessage());
      }
    }
    if (messages.isEmpty()) {
      form.commit();
      callback.onSave(item);
    }
    else {
      StringBuilder sb = new StringBuilder();
      for (String msg : messages.values()) {
        sb.append(msg).append("<br/>");
      }
      validationNotification(getApplication(), getI18NSource(), sb.toString());
    }
  }
});

代码示例来源:origin: org.vaadin.addons/customfield

public void validate() throws InvalidValueException {
  if (property instanceof Validatable) {
    if (isEmpty()) {
      if (isRequired()) {
        throw new Validator.EmptyValueException(getRequiredError());
      } else {
        return;
      }
    }
    if (converter != null) {
      converter.validate(getValue());
    } else {
      ((Validatable) property).validate();
    }
  } else {
    wrappedField.validate();
  }
}

代码示例来源:origin: org.opennms.features.vaadin-components/core

/**
 * Validates the given field and sets the component error accordingly.
 * Please note, that the provided field must implement {@link Field} and must be a sub class of {@link AbstractComponent}.
 *
 * @param field The field to validate (must be a sub class of {@link AbstractComponent}).
 * @param swallowValidationExceptions Indicates if an InvalidValueException is swallowed and not propagated.
 *                             If false the first occurring InvalidValueException is thrown.
 * @throws Validator.InvalidValueException If the field is not valid (see {@link Validator#validate(Object)}.
 */
public static void validateField(Field<?> field, boolean swallowValidationExceptions) throws Validator.InvalidValueException {
  if (field instanceof AbstractComponent && field.isEnabled()) {
    try {
      field.validate();
      ((AbstractComponent) field).setComponentError(null);
    } catch (Validator.InvalidValueException ex) {
      // Some fields unify exceptions, we have to consider this
      if (ex.getMessage() == null) {
        ex = ex.getCauses()[0];
      }
      // set error message
      ((AbstractComponent) field).setComponentError(new UserError(ex.getMessage()));
      if (!swallowValidationExceptions) {
        throw ex;
      }
    }
  }
}

相关文章