List of usage examples for com.vaadin.data Binder forField
public <FIELDVALUE> BindingBuilder<BEAN, FIELDVALUE> forField(HasValue<FIELDVALUE> field)
From source file:org.jpos.qi.minigl.NewEntryForm.java
License:Open Source License
private void createAndBindFields(Binder binder) { TextField accountCode = createTextField("accountCode"); ComboBox layer = createLayersSelector(); TextField detail = createTextField("detail"); TextField tags = createTextField("tags"); TextField amount = createTextField("amount"); RadioButtonGroup credit = createCreditOrDebit(); binder.forField(accountCode).withNullRepresentation("").withConverter(new AccountConverter()) .withValidator((Validator<Account>) (value, context) -> { if (value != null && !(value instanceof FinalAccount)) return ValidationResult.error(app.getMessage("errorMessage.accountNotFinal")); else if (value == null) return ValidationResult.error(app.getMessage("errorMessage.req", StringUtils.capitalize(accountCode.getCaption()))); return ValidationResult.ok(); }).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)// w w w. jav a 2 s. co m .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"))) .withValidator(new BigDecimalRangeValidator(app.getMessage("errorMessage.invalidAmount"), new BigDecimal("1"), new BigDecimal("99999999999999"))) .withNullRepresentation(BigDecimal.ZERO).bind("amount"); binder.bind(credit, "credit"); addComponent(accountCode); addComponent(layer); addComponent(detail); addComponent(tags); addComponent(amount); addComponent(credit); setComponentAlignment(credit, Alignment.BOTTOM_CENTER); }
From source file:org.jpos.qi.sysconfig.SysConfigView.java
License:Open Source License
@Override protected Component buildAndBindCustomComponent(String propertyId) { if ("id".equals(propertyId)) { TextField id = new TextField(getCaptionFromId(propertyId)); List<Validator> validators = 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);// w w w . j a v a 2 s . co m return id; } return null; }
From source file:org.jpos.qi.system.RevisionsView.java
License:Open Source License
@Override protected Component buildAndBindCustomComponent(String propertyId) { List<Validator> validators = getValidators(propertyId); ReadOnlyField field = new ReadOnlyField(); field.setCaption(getCaptionFromId(propertyId)); Binder binder = getBinder(); Binder.BindingBuilder builder = binder.forField(field).withNullRepresentation(""); if ("author".equals(propertyId)) { builder = builder.withConverter(userInput -> userInput, (SerializableFunction<User, String>) toPresentation -> ((RevisionsHelper) getHelper()) .getAuthorLink(toPresentation.getNickAndId(), String.valueOf(getInstance().getId()))); }/*from w ww .j av a 2 s . c om*/ if ("ref".equals(propertyId)) { builder = builder.withConverter(userInput -> userInput, (SerializableFunction<String, String>) toPresentation -> ((RevisionsHelper) getHelper()) .getLink(toPresentation, String.valueOf(getInstance().getId()))); } validators.forEach(builder::withValidator); builder.bind(propertyId); return field; }
From source file:uk.q3c.krail.testapp.view.AccountsView.java
License:Apache License
public void fake() { Binder<Person> binder = new Binder<>(); TextField titleField = new TextField(); // Start by defining the Field instance to use binder.forField(titleField) // Finalize by doing the actual binding to the Person class .bind(// ww w . j a v a 2s .com // Callback that loads the title from a person instance Person::getTitle, // Callback that saves the title in a person instance Person::setTitle); TextField nameField = new TextField(); // Shorthand for cases without extra configuration binder.bind(nameField, Person::getName, Person::setName); }