2 Replies Latest reply on Dec 18, 2014 3:10 AM by Lukas Herman

    @Templated on fields

    Lukas Herman Newbie

      Hello,

      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

        • 1. Re: @Templated on fields
          Christian Sadilek Master

          Hi Lukas,

           

          It definitely does make sense to me. What I am not sure about is whether or not the feature is "important" enough and justifies adding/maintaining the additional complexity. In the example above, would you generate a separate subtype of each @Templated field injection point of EditableField or find a way to reuse them for different injection points?

           

          Cheers,

          Christian

          • 2. Re: @Templated on fields
            Lukas Herman Newbie

            Hi Christian,

            This feature is definitely not so much important, simply just because a generic solution exists for the problem. I have not analyzed yet the generator for templated components to estimate the work needed to implement it. Anyway it seems too specific for my use case.

            The reason for not using reusable classes is that layout for EditableField is defined in the template html file. Moving the layout metadata out from the template to the generic component would require additional tweaks in the code to make it appear exactly the same as the template defines. It breaks WYSIWYG approach for designing application forms.

            On the other side, using static inner classes for component templates is very helpful in case of implementing <select> fields (possibly any other dynamic list type fields), where the fields always needs to be customized for additional data access. Probably later in the application prototyping stage, the use case for generic @Templated fields becomes completely invalid.

             

            Thanks for your opinion.

            Lukas