Annotation Type ProvidesProperty


  • @Retention(RUNTIME)
    @Target({METHOD,FIELD})
    @Documented
    public @interface ProvidesProperty
    Provides the information necessary to auto-generate a PropertyDefinition based on the annotated getter method.

    @ProvidesProperty method annotations can be used to automatically generate a PropertySet's using a ProvidesPropertyScanner. The resulting PropertySet can then be provided to Grid.withPropertySet() for example.

    This annotation indicates that a read-only Vaadin PropertyDefinition having the type equal to the method's return type is accessible by reading that method. Annotated methods must have zero parameters.

    For example:

    
     // Container backing object class
     public class User {
    
         public static final String USERNAME_PROPERTY = "username";
         public static final String REAL_NAME_PROPERTY = "realName";
    
         private String username;
         private String realName;
    
         public String getUsername() {
             return this.username;
         }
         public void setUsername(String username) {
             this.username = username;
         }
    
         @ProvidesProperty                     // property name "realName" is implied
         public String getRealName() {
             return this.realName;
         }
         public void setRealName(String realName) {
             this.realName = realName;
         }
    
         @ProvidesProperty(USERNAME_PROPERTY)  // display usernames in fixed-width font
         private Label usernameProperty() {
             return new Label("<code>" + StringUtil.escapeHtml(this.username) + "</code>", ContentMode.HTML);
         }
     }
    
     // Build Grid showing users with auto-generated properties
     Grid<User> grid = Grid.withPropertySet(new ProvidesPropertyScanner(User.class).getPropertySet());
     grid.setVisibleColumns(User.USERNAME_PROPERTY, User.REAL_NAME_PROPERTY);
     ...
     

    Some details regarding @ProvidesProperty annotations:

    • Only non-void methods taking zero parameters are supported; @ProvidesProperty annotations on other methods are ignored
    • Protected, package private, and private methods are supported.
    • @ProvidesProperty annotations declared in super-types (including interfaces) are supported
    • If a method and the superclass or superinterface method it overrides are both annotated with @ProvidesProperty, then the overridding method's annotation takes precedence.
    • If two methods with different names are annotated with @ProvidesProperty for the same property name, then the declaration in the class which is a sub-type of the other wins (if the two classes are equal or not comparable, an exception is thrown). This allows subclasses to "override" which method supplies a given property.
    See Also:
    ProvidesPropertyScanner
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      String caption
      Get the caption for the Vaadin property.
      String value
      Get the name of the Vaadin property.
    • Element Detail

      • value

        String value
        Get the name of the Vaadin property.

        If this is left unset (empty string), then the bean property name of the annotated bean property "getter" method is used.

        Returns:
        property name
        Default:
        ""
      • caption

        String caption
        Get the caption for the Vaadin property.

        If this is left unset (empty string), then the name of the property is used.

        Returns:
        property caption
        Default:
        ""