4 Replies Latest reply on Jun 12, 2014 4:48 AM by Pere Fernández Pérez

    errai templates from database

    Vasco Andrade e Silva Newbie

      Hi all,


      Is it possible with errai (or an errai library) to make HTML5 templates from remote data sources (like a web service)?


      An example would be:

      1) In some screen of the app, the user is able to create/edit errai temples (via a web-base form field)

      2) those templates were stored in some database

      3) those templates were by the app to render some information


      Steps 1) and 2) are OK. I currently don't know is how can I do Step 3) with the maximum errai support.


      Thank you for your comments.




        • 1. Re: errai templates from database
          Jonathan Fuerth Master

          Hi Vasco,


          Using a self-provided template isn't quite possible with Errai today, but it wouldn't be a very big change to the framework if you wanted to add this feature. The generated code that performs the parse-and-composite process uses a hardcoded call to GWT.create() to get the String containing the HTML template. After that, everything is done in a way that would work fine with HTML that was fetched (or even generated) at runtime.


          So the trick would be to modify Errai UI's code generator in a way that lets you specify something other than a filename as the source of the template. Perhaps something like this:


          public class MyDynamicTemplatedWidget extends Composite {
            @Inject @DataField TextBox blah;
            // etc.


          Then Errai would have a TemplateProvider interface that template providers would implement:


          public interface TemplateProvider {
           String templateFor(Class<? extends Composite> widgetClass);


          Passing the widget type to the provider method gives application developers the option to implement one super-provider for all dynamic template types, but leaves open the possibility to create a separate provider class for each dynamic templated widget.


          With this idea, the net change to the generated code would only be two lines (the line that invokes GWT.create(), and the line after that gets the text out of the resource). But this is just one possible implementation idea. Maybe you or others have a counersuggestion about how to do this


          The downside to all of this is that compile-time type safety goes out the window. There's no way to prove at compile time that the provider will always provide a template that contains all the elements required by the @DataField fields of the widget class.


          Is this something you'd be interested in taking on? We love pull requests!



          • 2. Re: errai templates from database
            Vasco Andrade e Silva Newbie

            Jonathan, thank you for your answer - it was right on the spot - and sorry for my delay answering this thread. I've been looking with my colleagues to include this development in the project that needs this. Once we do it (may take a couple of month) we'll do a pull request.


            Thanks once again.

            • 3. Re: errai templates from database
              Anton Hughes Master

              Hi Jonathan!


              Great idea! This would be a great feature for Errai!

              • 4. Re: errai templates from database
                Pere Fernández Pérez Newbie

                Hi Jonathan,


                is there any new about this?


                I work on the jbpm-form-modeler and it would be great if we can develope the new version based on this.