List of usage examples for com.vaadin.v7.ui Field setRequired
public void setRequired(boolean required);
From source file:de.symeda.sormas.ui.utils.AbstractEditForm.java
License:Open Source License
protected void setRequired(boolean required, String... fieldOrPropertyIds) { for (String propertyId : fieldOrPropertyIds) { Field<?> field = getField(propertyId); field.setRequired(required); }/*from ww w.j ava 2s . c om*/ }
From source file:de.symeda.sormas.ui.utils.FieldHelper.java
License:Open Source License
/** * Sets the target fields to required when the sourceField has a value that's * contained in the sourceValues list; the disease is needed to make sure that * no fields are set to required that are not visible and therefore cannot be * edited by the user.// w w w. ja v a2 s . com */ @SuppressWarnings("rawtypes") public static void setRequiredWhen(FieldGroup fieldGroup, Field sourceField, List<String> targetPropertyIds, final List<Object> sourceValues, boolean requiredWhenNot, Disease disease) { if (sourceField instanceof AbstractField<?>) { ((AbstractField) sourceField).setImmediate(true); } // initialize { boolean required = sourceValues.contains(sourceField.getValue()); required = required != requiredWhenNot; for (Object targetPropertyId : targetPropertyIds) { Field targetField = fieldGroup.getField(targetPropertyId); if (!targetField.isVisible()) { targetField.setRequired(false); continue; } if (disease == null || Diseases.DiseasesConfiguration.isDefined(SymptomsDto.class, (String) targetPropertyId, disease)) { targetField.setRequired(required); } } } sourceField.addValueChangeListener(event -> { boolean required = sourceValues.contains(event.getProperty().getValue()); required = required != requiredWhenNot; for (Object targetPropertyId : targetPropertyIds) { Field targetField = fieldGroup.getField(targetPropertyId); if (!targetField.isVisible()) { targetField.setRequired(false); continue; } if (disease == null || Diseases.DiseasesConfiguration.isDefined(SymptomsDto.class, (String) targetPropertyId, disease)) { targetField.setRequired(required); } } }); }
From source file:de.symeda.sormas.ui.utils.FieldHelper.java
License:Open Source License
public static void setFirstRequired(Field<?> first, Field<?>... others) { if (first != null) { first.setRequired(true); }//from w w w . j a v a 2 s . c om for (Field<?> other : others) { other.setRequired(false); } }
From source file:org.vaadin.viritin.v7.MBeanFieldGroup.java
License:Apache License
/** * Configures fields for some better defaults, like property fields * annotated with NotNull to be "required" (kind of a special validator in * Vaadin)//w w w.jav a 2s . c o m */ public void configureMaddonDefaults() { for (Object property : getBoundPropertyIds()) { final Field<?> field = getField(property); try { // Make @NotNull annotated fields "required" try { java.lang.reflect.Field declaredField = findDeclaredField(property, nonHiddenBeanType); final NotNull notNullAnnotation = declaredField.getAnnotation(NotNull.class); if (notNullAnnotation != null && !field.isReadOnly()) { field.setRequired(true); Locale locale = getLocale(); if (locale == null) { locale = Locale.getDefault(); } String msg = getJavaxBeanValidatorFactory().getMessageInterpolator() .interpolate(notNullAnnotation.message(), new MessageInterpolator.Context() { @Override public ConstraintDescriptor<?> getConstraintDescriptor() { return null; } @Override public Object getValidatedValue() { return null; } @Override public <T> T unwrap(Class<T> type) { return null; } }, locale); getField(property).setRequiredError(msg); } } catch (NoSuchFieldException ex) { Logger.getLogger(MBeanFieldGroup.class.getName()).log(Level.FINE, null, ex); } catch (SecurityException ex) { Logger.getLogger(MBeanFieldGroup.class.getName()).log(Level.SEVERE, null, ex); } } catch (Throwable e) { if (e instanceof java.lang.ClassNotFoundException) { Logger.getLogger(MBeanFieldGroup.class.getName()).log(Level.FINE, "Validation API not available."); } } } }