You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PropertyId.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.annotations;
  17. import java.lang.annotation.ElementType;
  18. import java.lang.annotation.Retention;
  19. import java.lang.annotation.RetentionPolicy;
  20. import java.lang.annotation.Target;
  21. import com.vaadin.data.Binder;
  22. import com.vaadin.data.HasValue;
  23. /**
  24. * Defines the custom property name to be bound to a {@link HasValue field
  25. * component} using {@link Binder}.
  26. * <p>
  27. * The automatic data binding in Binder relies on a naming convention by
  28. * default: properties of an item are bound to similarly named field components
  29. * in given a editor object. If you want to map a property with a different name
  30. * (ID) to a {@link HasValue}, you can use this annotation for the member
  31. * fields, with the name (ID) of the desired property as the parameter.
  32. * <p>
  33. * In following usage example, the text field would be bound to property "foo"
  34. * in the Entity class.
  35. * <pre>
  36. class Editor extends FormLayout {
  37. &#64;PropertyId("foo")
  38. TextField myField = new TextField();
  39. }
  40. class Entity {
  41. String foo;
  42. }
  43. {
  44. Editor editor = new Editor();
  45. Binder&lt;Entity&gt; binder = new Binder(Entity.class);
  46. binder.bindInstanceFields(editor);
  47. }
  48. </pre>
  49. *
  50. * @since 8.0
  51. * @author Vaadin Ltd
  52. */
  53. @Target({ ElementType.FIELD })
  54. @Retention(RetentionPolicy.RUNTIME)
  55. public @interface PropertyId {
  56. String value();
  57. }