This content has been marked as final.
Show 3 replies
-
1. Re: Data binding for element attributes?
mbarkley May 10, 2016 5:17 PM (in response to hr.stoyanov)Hi Hristo,
We have an example of that you can look at in Errai Tutorial. Here is a JS interop wrapper for an anchor element that supports data-binding to its href property.
Key things to note:
- The @Element("a") makes this injectable (satisfied by an anchor tag).
- It implements a special HasValue interface for native JS types.
- Any @Bound @JsType implementing this HasValue interface will use the HasValue methods for data-binding operations.
- This example uses @JsOverlay methods because the JavaScript HTMLAnchorElement doesn't actually have getValue and setValue methods but you could also:
- Not use overlay methods for JavaScript objects that have "getValue" and "setValue" methods.
- Not implement the HasValue methods and use @JsProperty so that calls to getValue and setValue are compiled to property accesses and assignments.
Cheers.
-
2. Re: Data binding for element attributes?
hr.stoyanov May 11, 2016 4:17 PM (in response to mbarkley)Thanks Max,
Why does the class need to be abstract?
-
3. Re: Data binding for element attributes?
mbarkley May 11, 2016 4:59 PM (in response to hr.stoyanov)It doesn't have to be abstract. However, since it is an HTML element you can't create instances via the constructor (calling the constructor in GWT code compiles to "new HTMLAnchorElement()" in JavaScript which causes an error since elements can only be created by the document). So making it abstract is just a way of enforcing proper usage (i.e. only getting instances via injection).