List of usage examples for com.vaadin.data.validator BeanValidator BeanValidator
public BeanValidator(Class<?> beanType, String propertyName)
From source file:com.aaron.mbpet.views.users.UserEditor.java
License:Apache License
@Override public Field createField(Item item, Object propertyId, Component uiContext) { Field field = (TextField) DefaultFieldFactory.get().createField(item, propertyId, uiContext); // if ("department".equals(propertyId)) { // field = new DepartmentSelector(); // } else if (field instanceof TextField) { if ("firstname".equals(propertyId)) { field.focus();/*from w w w.j a va 2 s . co m*/ } else if ("username".equals(propertyId)) { field.addValidator(new UsernameValidator()); } else if ("password".equals(propertyId)) { field.addValidator(new PasswordValidator()); } //else if ("email".equals(propertyId)) { // field.addValidator(new EmailValidator( // "must be an email address")); // } if (editMode == true && ("username".equals(propertyId) || "password".equals(propertyId))) { field.setEnabled(false); //setReadOnly(true); } ((TextField) field).setNullRepresentation(""); // ((TextField) field).setValidationVisible(false); } field.addValidator(new BeanValidator(User.class, propertyId.toString())); return field; }
From source file:com.moorevaadin.vaadin7.beanvalidation.ValidatorUtils.java
License:Apache License
static void installSingleValidator(Field<?> field, String attribute) { Collection<Validator> validators = field.getValidators(); if (validators == null || validators.isEmpty()) { field.addValidator(new BeanValidator(Person.class, attribute)); }//from w w w . j a v a 2s. c o m }
From source file:com.ocs.dynamo.domain.model.impl.ModelBasedFieldFactory.java
License:Apache License
/** * Creates a field/* w w w . j ava2 s. co m*/ * * @param propertyId * the name of the property that can be edited by this field * @param fieldEntityModel * the custom entity model for the field * @return */ public Field<?> createField(String propertyId, EntityModel<?> fieldEntityModel) { // in case of a read-only field, return <code>null</code> so Vaadin will // render a label instead AttributeModel attributeModel = model.getAttributeModel(propertyId); if (attributeModel.isReadOnly() && (!attributeModel.isUrl() && !AttributeType.DETAIL.equals(attributeModel.getAttributeType())) && !search) { return null; } Field<?> field = null; if (AttributeTextFieldMode.TEXTAREA.equals(attributeModel.getTextFieldMode()) && !search) { // text area field field = new TextArea(); } else if (attributeModel.isWeek()) { // special case - week field in a table TextField tf = new TextField(); tf.setConverter(new WeekCodeConverter()); field = tf; } else if (search && attributeModel.getType().equals(Boolean.class)) { // in a search screen, we need to offer the true, false, and // undefined options field = constructSearchBooleanComboBox(attributeModel); } else if (AbstractEntity.class.isAssignableFrom(attributeModel.getType())) { // lookup or combo field for an entity field = constructSelectField(attributeModel, fieldEntityModel, null); } else if (AttributeType.ELEMENT_COLLECTION.equals(attributeModel.getAttributeType())) { // use a "collection table" for an element collection FormOptions fo = new FormOptions(); fo.setShowRemoveButton(true); if (String.class.equals(attributeModel.getMemberType())) { CollectionTable<String> table = new CollectionTable<>(false, fo, String.class); table.setMinLength(attributeModel.getMinLength()); table.setMaxLength(attributeModel.getMaxLength()); field = table; } else if (Integer.class.equals(attributeModel.getMemberType())) { CollectionTable<Integer> table = new CollectionTable<>(false, fo, Integer.class); field = table; } else { // other types not supported for now throw new OCSRuntimeException(); } } else if (Collection.class.isAssignableFrom(attributeModel.getType())) { // render a multiple select component for a collection field = constructCollectionSelect(attributeModel.getNestedEntityModel(), attributeModel, null, true, search); } else if (AttributeDateType.TIME.equals(attributeModel.getDateType())) { TimeField tf = new TimeField(); tf.setResolution(Resolution.MINUTE); tf.setLocale(VaadinSession.getCurrent() == null ? DynamoConstants.DEFAULT_LOCALE : VaadinSession.getCurrent().getLocale()); field = tf; } else if (attributeModel.isUrl()) { // URL field (offers clickable link in readonly mode) TextField tf = (TextField) createField(attributeModel.getType(), Field.class); tf.addValidator(new URLValidator(messageService.getMessage("ocs.no.valid.url"))); tf.setNullRepresentation(null); tf.setSizeFull(); // wrap text field in URL field field = new URLField(tf, attributeModel, false); field.setSizeFull(); } else { // just a regular field field = createField(attributeModel.getType(), Field.class); } field.setCaption(attributeModel.getDisplayName()); postProcessField(field, attributeModel); // add a field validator based on JSR-303 bean validation if (validate) { field.addValidator(new BeanValidator(model.getEntityClass(), (String) propertyId)); // disable the field if it cannot be edited if (!attributeModel.isUrl()) { field.setEnabled(!attributeModel.isReadOnly()); } if (attributeModel.isNumerical()) { field.addStyleName(DynamoConstants.CSS_NUMERICAL); } } return field; }
From source file:cz.zcu.pia.social.network.frontend.components.login.ComponentRegister.java
/** * Adds validators//from w w w . j av a 2 s . c o m */ private void addValidators() { name.addValidator(new BeanValidator(RegisterBean.class, "name")); surname.addValidator(new BeanValidator(RegisterBean.class, "surname")); username.addValidator(new BeanValidator(RegisterBean.class, "username")); password.addValidator(new BeanValidator(RegisterBean.class, "password")); passwordRepeat.addValidator(new BeanValidator(RegisterBean.class, "passwordRepeat")); validation.addValidator(new BeanValidator(RegisterBean.class, "validation")); }
From source file:fr.amapj.view.engine.basicform.BasicFormListPart.java
License:Open Source License
protected Field addFieldText(FormInfo formInfo, String propertyId, String title) { Field f = formInfo.binder.buildAndBind(title, propertyId); f.addValidator(new BeanValidator(getClazz(), propertyId)); ((TextField) f).setNullRepresentation(""); ((TextField) f).setStyleName(ChameleonTheme.TEXTFIELD_BIG); ((TextField) f).setWidth("80%"); formInfo.form.addComponent(f);/*from w w w. ja va2 s . co m*/ return f; }
From source file:rds.vaadin.beanfaces.BeanFace.java
License:Apache License
/** * Overide to provide custom validators for field. * //from w w w . j a v a 2s.com * @param fieldConfig * @param activate */ protected void activateValidator(FieldDefinition fieldConfig, boolean activate) { PropertyKind propertyKind = fieldConfig.getKind(); // Keep only non associative fields if (!formDef.isExcludable(propertyKind)) { if (activate) { getField(fieldConfig.getPropertyName()).addValidator( new BeanValidator(formDef.getEntityClass(), fieldConfig.getPropertyName().toString())); } else { getField(fieldConfig.getPropertyName()).removeAllValidators(); } } }