Annotation Interface AbstractFieldBuilder.FieldDefault
- Enclosing class:
- AbstractFieldBuilder<S extends AbstractFieldBuilder<S,
T>, T>
@FieldBuilder
.
A @FieldBuilder.FieldDefault
annotation annotates a static method in an
edited model class that returns an alternate default value for some field configuration property, for example,
"itemLabelGenerator"
.
The property is specified by name and works for all Vaadin field types having a corresponding setter method whose parameter type is compatible with the annotated method's return type.
For example:
// This is one of our data model classes
public class Person {
public String getFirstName() { ... }
public String getLastName() { ... }
@FieldBuilder.FieldDefault("itemLabelGenerator")
private static ItemLabelGenerator<Person> itemLabel() {
return person -> person.getLastName() + ", " + person.getFirstName();
}
}
// This is a class we want to edit using FieldBuilder
-generated fields
public class Vehicle {
@FieldBuilder.ComboBox // Does not use any special ItemLabelGenerator
public Model getModel() { ... }
@FieldBuilder.ComboBox( // Uses an instance of AnotherClass as ItemLabelGenerator
itemLabelGenerator = AnotherClass.class)
public Person getOwner() { ... }
@FieldBuilder.ComboBox // Uses ItemLabelGenerator from Person.itemLabel()
public Person getOwner() { ... }
@FieldBuilder.CheckboxGroup // Uses ItemLabelGenerator from Person.itemLabel()
public Person getPassengers() { ... }
}
Details
The annotated method must be static, take zero parameters, and have a return type compatible with the named field property, or else the annotation is ignored. Public, package-private, protected, and private methods are supported.
These method may be declared in the edited model class, or any superclass thereof. If the same property is named by multiple methods, the method declared in the narrower declaring class wins. If neither declaring class is narrower, an exception is thrown.
These annotations only affect fields created from @FieldBuilder.Foo
declarative annotations;
fields returned by @FieldBuilder.ProvidesField
methods are not affected.
-
Required Element Summary
-
Element Details
-
value
String valueThe name of the field property that the annotated method will provide.- Returns:
- field property name
-