/** * Creates a new binding for the given field. The returned builder may be * further configured before invoking {@link #bindInstanceFields(Object)}. * Unlike with the {@link #forField(HasValue)} method, no explicit call to * {@link BindingBuilder#bind(String)} is needed to complete this binding in * the case that the name of the field matches a field name found in the * bean. * * @param <FIELDVALUE> * the value type of the field * @param field * the field to be bound, not null * @return the new binding builder * * @see #forField(HasValue) * @see #bindInstanceFields(Object) */ public <FIELDVALUE> BindingBuilder<BEAN, FIELDVALUE> forMemberField( HasValue<FIELDVALUE> field) { incompleteMemberFieldBindings.put(field, null); return forField(field); }
return forField(field).bind(propertyName);
HasValue<FIELDVALUE> field, ValueProvider<BEAN, FIELDVALUE> getter, Setter<BEAN, FIELDVALUE> setter) { return forField(field).bind(getter, setter);
initializeField(objectWithMemberFields, memberField, field); forField(field).bind(property); return true; } else {
@Override protected Component buildAndBindCustomComponent(String propertyId) { List<Validator> validators = getFieldFactory().getValidators(propertyId); if ("permissions".equals(propertyId)) { CheckBoxGroup<Permission> f = new CheckBoxGroup("Permissions"); List<SysConfig> sysconfigs = ((RolesHelper)getHelper()).getPermissions(); List<Permission> allPermissions = new ArrayList<>(); //convert SysConfigs to Permissions for (SysConfig sys : sysconfigs) { Permission p = Permission.valueOf(sys.getId().substring(5)); allPermissions.add(p); } f.setItems(allPermissions); f.setItemCaptionGenerator((ItemCaptionGenerator<Permission>) item -> sysconfigs.get(allPermissions.indexOf(item)).getId().substring(5) + " : " + //remove "perm." prefix sysconfigs.get(allPermissions.indexOf(item)).getValue()); Binder.BindingBuilder builder = getBinder().forField(f); validators.forEach(builder::withValidator); builder.bind(propertyId); return f; } return null; }
protected Component buildAndBindCustomComponent(String propertyId) { if ("roles".equals(propertyId)) { CheckBoxGroup g = new CheckBoxGroup(StringUtils.capitalize(getCaptionFromId(propertyId))); g.setItems(((UsersHelper)getHelper()).getRoles()); g.setItemCaptionGenerator((ItemCaptionGenerator<Role>) item -> StringUtils.capitalize(item.getName())); List<Validator> v = getFieldFactory().getValidators(propertyId); Binder.BindingBuilder builder = getBinder().forField(g); for (Validator val : v) { builder.withValidator(val); } builder.bind(propertyId); return g; } return null; }
@Override protected Component buildAndBindCustomComponent(String propertyId) { if ("id".equals(propertyId)) { TextField id = new TextField(getCaptionFromId(propertyId)); List<Validator> validators = getFieldFactory().getValidators(propertyId); Binder<SysConfig> binder = getBinder(); Binder.BindingBuilder builder = binder.forField(id) .asRequired(getApp().getMessage("errorMessage.req", StringUtils.capitalize(getCaptionFromId(propertyId)))) .withNullRepresentation("") .withConverter(userInputValue -> userInputValue , toPresentation -> removePrefix(toPresentation)); validators.forEach(builder::withValidator); builder.bind(propertyId); return id; } return null; }
/** * onstructs the entity edit form for the data entity * @param beanType The class of the data entity * @param idIsEditable Whether the id is editable */ public AbstractEntityEditForm( final Class<T> beanType, final boolean idIsEditable) { this.binder = new Binder<>(beanType); if (idIsEditable) { this.binder.forField(idField) //.withConverter(new StringToLongConverter("Unable to convert id")) .asRequired("The id field is required.") .bind("id"); } else { this.binder.forField(idField) //.withConverter(new StringToLongConverter("Unable to convert id")) .bind("id"); } this.binder.addStatusChangeListener(this::onBinderStatusChange); setSpacing(true); setMargin(false); setSizeFull(); Responsive.makeResponsive(this); idField.setReadOnly(!idIsEditable); idField.setWidth(100.0f, Unit.PERCENTAGE); }
Optional.ofNullable(editor).map(ColumnEditorDefinition::getField).ifPresent(field -> { final HasValue component = formFieldFactory.createField(field, Locale.getDefault()); final Binder.BindingBuilder<T, ?> bindingBuilder = grid.getEditor().getBinder().forField(component);
@SuppressWarnings({ "unchecked", "rawtypes" }) private void setEditorBinding(P property, Column column, HasValue editor, boolean readOnly, PropertyColumn<?, ?> pc) { BindingBuilder builder = getGrid().getEditor().getBinder().forField(editor); if (pc.isRequired()) { final Localizable requiredMessage = (pc.getRequiredMessage() != null) ? pc.getRequiredMessage() : RequiredInputValidator.DEFAULT_REQUIRED_ERROR; builder.asRequired(context -> { return LocalizationContext.translate(requiredMessage, true); }); } // default validators getDefaultPropertyValidators(property).forEach(v -> builder.withValidator(new ValidatorWrapper<>(v))); // validators pc.getValidators().forEach(v -> builder.withValidator(v)); // bind column.setEditorBinding(builder.bind(getColumnId(property))); // set editable if not read-only column.setEditable(!readOnly); }
TextField amount = createTextField("amount"); RadioButtonGroup credit = createCreditOrDebit(); binder.forField(accountCode) .withNullRepresentation("") .withConverter(new AccountConverter()) .asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(layer.getCaption()))) .bind("account"); binder.forField(layer) .withConverter(new ShortToLayerConverter(journal)) .asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(layer.getCaption()))) .bind("layer"); binder.forField(detail) .withValidator(new StringLengthValidator(app.getMessage("errorMessage.invalidField", detail.getCaption()), 0, 255)) .withValidator(new RegexpValidator(app.getMessage("errorMessage.invalidField", detail.getCaption()), TEXT_REGEX)) .bind("detail"); binder.forField(tags) .withValidator(new StringLengthValidator(app.getMessage("errorMessage.invalidField", tags.getCaption()), 0, 255)) .withValidator(new RegexpValidator(app.getMessage("errorMessage.invalidField", tags.getCaption()), TEXT_REGEX)) .withConverter(new StringToTagConverter()) .bind("tags"); binder.forField(amount) .asRequired(app.getMessage("errorMessage.req", StringUtils.capitalize(amount.getCaption()))) .withConverter(new StringToBigDecimalConverter(app.getMessage("errorMessage.invalidAmount")))
private void initialize() { optionsField = formFieldFactory.createField(definition.getField(), locale); layout.addComponent(optionsField); optionsField.addValueChangeListener(e -> { if (e.getOldValue() == null || e.getOldValue() == null) { return; } EditorView<T> oldView = subForm(e.getOldValue()); EditorView<T> newView = subForm(e.getValue()); layout.replaceComponent(oldView.asVaadinComponent(), newView.asVaadinComponent()); }); definition.getForms().forEach(formDefinition -> { ItemProviderStrategy<T> subFormProviderStrategy = create(((ComplexPropertyDefinition<T>) formDefinition).getItemProvider(), formDefinition, itemProviderStrategy); EditorView<T> subForm = getViewProvider().create(formDefinition); subForms.put(formDefinition.getName(), Pair.of(subForm, subFormProviderStrategy)); }); binder = ConfiguredBinder.withPropertySet(propertySetFactory.fromFieldDefinitions(Collections.singletonList(definition.getField()), locale)); binder.forField(optionsField) .withConverter(new StringToOptionDefinitionConverter(definition.getField())) .bind(resolvePropertyNameByLocale(definition.getField().getName(), locale, definition.getField().isI18n())); }
currentPasswordField.setWidth("80%"); passwordBinder.forField(currentPasswordField) .asRequired(getApp().getMessage("errorMessage.req", currentPasswordField.getCaption())) .withValidator(((UsersHelper)getHelper()).getCurrentPasswordMatchValidator()) passwordBinder.forField(newPasswordField) .asRequired(getApp().getMessage("errorMessage.req",newPasswordField.getCaption())) .withValidator(((UsersHelper)getHelper()).getNewPasswordNotUsedValidator()) passwordBinder.forField(repeatPasswordField) .asRequired(getApp().getMessage("errorMessage.req", repeatPasswordField.getCaption())) .withValidator(((UsersHelper)getHelper()).getPasswordsMatchValidator(newPasswordField))
getBinder().forField(entryGrid) .bind(glTransaction -> this.getInstance(), null); if (getInstance() != null && getInstance().getJournal() != null) {