Beispiel #1
0
    @Override
    public Field createField(Item item, Object propertyId, Component uiContext) {
      Field f;
      if (UserEditProfileData.LOCALE_PROPERTY.equals(propertyId)) {
        return this.localeSelect;
      } else if (UserEditProfileData.ROLE_PROPERTY.equals(propertyId)) {
        return this.roleSelect;
      } else {
        // Use the super class to create a suitable field base on the
        // property type.
        f = super.createField(item, propertyId, uiContext);
        f.addStyleName("gaemvnrepo-form-input");
      }

      if (UserEditProfileData.LOGIN_PROPERTY.equals(propertyId)) {
        TextField tf = (TextField) f;
        tf.setRequired(true);
        tf.setRequiredError(ApplicationData.getMessage("UserEditView.required.login"));
        tf.addValidator(
            new StringLengthValidator(
                ApplicationData.getMessage("UserEditView.invalid.login"), 3, 25, false));
      } else if (UserEditProfileData.EMAIL_PROPERTY.equals(propertyId)) {
        TextField tf = (TextField) f;
        tf.setRequired(true);
        tf.setRequiredError(ApplicationData.getMessage("UserEditView.required.email"));
        tf.addValidator(
            new EmailValidator(ApplicationData.getMessage("UserEditView.invalid.email")));
      }

      return f;
    }
 /**
  * Invokes the validation of the current field component. Adds the error style on validation
  * exception.
  */
 public void validate() {
   try {
     if (fieldComponent instanceof Field) {
       ((Field) fieldComponent).validate();
     } else if (fieldComponent instanceof FilterContainer) {
       ((FilterContainer) fieldComponent).validate();
     }
   } catch (InvalidValueException e) {
     if (fieldComponent instanceof Field) {
       ((Field) fieldComponent).addStyleName("error");
       ((Field) fieldComponent).removeStyleName("error");
     } else if (fieldComponent instanceof FilterContainer) {
       ((FilterContainer) fieldComponent).addStyleName("error");
       ((FilterContainer) fieldComponent).removeStyleName("error");
     }
   }
 }
 @Override
 public boolean validateForm() {
   boolean firstErrorFound = false;
   Set<PhysicalAttributeConfirmActualsFieldSetComponent> formFieldHeaders = headers.keySet();
   for (PhysicalAttributeConfirmActualsFieldSetComponent fieldSet : formFieldHeaders) {
     headers.get(fieldSet).removeStyleName("conx-form-header-error");
   }
   Set<Field> formFields = fields.keySet();
   for (Field field : formFields) {
     VaadinCollapsiblePhysicalAttributeConfirmActualsFormSectionHeader formFieldHeader =
         getFieldHeader(field);
     if (formFieldHeader != null) {
       try {
         field.validate();
         field.removeStyleName("conx-form-field-error");
       } catch (InvalidValueException e) {
         field.addStyleName("conx-form-field-error");
         formFieldHeader.addStyleName("conx-form-header-error");
         if (!firstErrorFound) {
           this.alertPanel.setMessage(e.getMessage());
           this.alertPanel.setVisible(true);
           firstErrorFound = true;
         }
       }
     }
   }
   if (firstErrorFound) {
     //			this.verifyButton.setEnabled(false);
     return false;
   } else {
     this.alertPanel.setVisible(false);
     //			this.verifyButton.setEnabled(false);
     //			this.saveButton.setEnabled(true);
     this.alertPanel.setAlertType(AlertType.SUCCESS);
     this.alertPanel.setMessage(this.header.getTitle() + " is valid.");
     this.alertPanel.setVisible(true);
     return true;
   }
 }