@Templated on fields
lukasherman Dec 10, 2014 6:02 AMHello,
There is a special use case for @Templated annotation on class fields. Having a complex UI with lots of custom components, I am facing a rather cosmetic problem. There is a master template.hml, custom components are based on dom tree snippets inside the template, not only simple data entry elements. Example:
CustomerDetail.html
<div data-field="main">
<form>
<div data-field="ident">
<div class="prefix"></div>
<div class="field"></div>
<div class="suffix"></div>
</div>
<div data-field="custType">
<div class="prefix"></div>
<div class="field"></div>
<div class="suffix"></div>
</div>
</form>
</div>
CustomerDetailTemplate.java
@Templated("CustomerDetail.html#main")
public class CustomerDetailTemplate extends Composite implements HasModel<Customer> {
@AutoBound @Inject DataBinder<Customer> customerDataBinder;
@Inject @DataField @Bound Ident ident;
@Inject @DataField @Bound CustType custType;
@Templated("CustomerDetail.html#ident")
public static class Ident extends EditableField {
}
@Templated("CustomerDetail.html#custType")
public static class CustType extends EditableField {
}
For simple use cases, where no functionality is overridden in EditableField, it would be much easier to mimic the exact behavior with:
CustomerDetailTemplate.java
@Templated("CustomerDetail.html#main")
public class CustomerDetailTemplate extends Composite implements HasModel<Customer> {
@AutoBound @Inject DataBinder<Customer> customerDataBinder;
@Inject @DataField @Bound @Templated EditableField ident;
@Inject @DataField @Bound @Templated("#custType") EditableField custType;
The current implementation works correctly, the classes are merged together with subtemplates, even overriding works. The code is just a little bit verbose.
The proposed change would introduce @Templated annotation on fields to build a templated custom component.
Does it make sense?
With regards
Lukas