Announcement Announcement Module
Collapse
No announcement yet.
Considering contributing Google Closure Templates for Spring MVC - please advise Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Considering contributing Google Closure Templates for Spring MVC - please advise

    I'm currently using Google Closure Templates with Spring MVC on a client project and it's working pretty well so I'm considering writing an open source version of the code to integrate the two.

    Obviously it'd be great if this could live alongside the Freemarker, Velocity etc. integration packages under Spring Web MVC.

    Please can anyone with any experience of submitting code to the Spring project advise me on the best way to proceed?

    And if there are any Spring committers reading this, can you comment on whether this is likely to be of interest?

    Many thanks,
    Tom

  • #2
    My advice would be to create a project on github that contains the source along with a basic sample showcase that demonstrates the value. You can then publish an article about it and we'll be happy to circulate it on springsource.org and via Twitter. From there, if there is enough community interest we can consider including it in an existing official Spring project, or bringing it under the SpringSource organization as a new project. I think this is interesting from the perspective of rendering the same views client and server-side.

    Keith

    Comment


    • #3
      Hi Tom,

      I'm was looking for a tutorial/example on how to use the Google Closure Templates with Spring MVC and came across this thread. Would you mind sharing your code or provide an example?

      All help is highly appreciated. Thank you!

      Comment


      • #4
        Hi Keith,

        Many thanks for the advice. I shall do as you suggest!

        Tom

        Comment


        • #5
          Great! Could you please post back the github url once it's up?

          Comment


          • #6
            Hi Gouki,

            Unfortunately my client won't allow me to share the code I've written for them. However, here's a brief description of what I've done:
            - Created a custom view class (by extending AbstractTemplateView), whose renderMergedTemplateModel method compiles all the templates (if necessary) using an injected Resource for the location, then renders the template indicated by getUrl() (which is actually just the view name). If you'll ever need your templates to be multi-lingual, you'll need to make sure you fetch the appropriate XLIFF file from your resources based on the locale e.g. messages_es.xlf, and create a SoyMessageBundle from this, which can be passed to the template's render() method.
            - Created a custom view resolver (by extending AbstractViewResolver) which builds the view. I'd suggest looking at the Freemarker View/ViewResolver stuff to get a better idea of how this should work. A gotcha I encountered here is that you must set view.setExposeSpringMacroHelpers to false here.
            - Created an MVC controller mapped to a URL like /my/app/templates/{templateName}.js, which compiles to JS and returns the corresponding .soy file i.e. /my/app/templates/homepage.js would return the JS for <templates_dir>/homepage.soy

            One thing to note is that because Closure Templates only accept SoyData or Map as inputs, you can't just put any POJOs in the model. We're currently converting our view model object graphs to maps before putting in the MVC model, but considering moving to an adapter pattern, using reflection to provide a Map interface to a graph of POJOs.

            I hope this gets you started at least.

            I should be putting up (project constraints permitting!) some initial code on Github over the next few weeks. I'll post the repo location on this thread when I do.

            Regards,
            Tom

            Comment


            • #7
              Thanks Tom!

              Those are useful advice I've tried googling for spring and closure combination and it doesn't seem to be much information out there.

              Looking forward to seeing the repo.

              Comment


              • #8
                Thanks you...

                I just wanted to mention that I'm very interested in using Closure with SpringMVC. Thanks for the good info.

                ---James

                Comment


                • #9
                  I've released an initial version of Spring Closure Templates: https://github.com/tomakehurst/spring-closure-templates

                  Check out the wiki for instructions on adding to a project, and the example app to see it in situ.

                  Feedback much appreciated!
                  Thanks,
                  Tom

                  Comment


                  • #10
                    Just wanted to thank you Tom for your work on this. Your project was about the only usable I could find about integrating mvc and closure templates. Really nice!

                    /janne

                    Comment


                    • #11
                      Glad it was helpful!

                      Comment

                      Working...
                      X