company-logo

Making Vaadin, PureMVC and Grails Work Together

On seeing that someone had developed a Grails Plugin for Vaadin (the former ITMill Toolkit, based on GWT as a front end technology), I immediately grabbed it and started exploring. One of the first things I do when developing things that look like GUI’s is apply PureMVC to it. It’s sort of like a big MVC switchboard that lets you hook together the smaller MVC’s of whatever framework you’re using. Overkill for really simple applications. Crucial for big ones.

Building a PureMVC app was pretty quick, but I ran into a small problem. Since PureMVC Multicore uses a Multiton pattern (essentially a map of Singletons), when Grails recompiles and restarts on code changes, the application barfs with a “Facade already constructed” runtime error. The solution is simple. In your subclassed org.puremvc.java.multicore.patterns.facade.Facade, change the following:

  public static ApplicationFacade getInstance() {
    if (instance == null) {
      instance = new ApplicationFacade(CORE)
    }
    return instance
  }

to this:

  public static ApplicationFacade getInstance() {
    if (instance == null) {
      // nuke the multiton so we can do the grails recompile
      if (ApplicationFacade.hasCore(CORE)) {
        ApplicationFacade.removeCore(CORE)
      }
      instance = new ApplicationFacade(CORE)
    }
    return instance
  }

And voila, your app now recompiles and runs without a hitch, just like a Grails app should. (CORE is a string constant to name your core.)

Related Services: Java Application Development, Custom Software Development

  1. Daniel Bell Reply

    Hi Dietrich, I’m really glad to see that you’ve used the plugin. What did you think of it? Any suggestions?
    Regards,
    Daniel

  2. Rodney Schneider Reply

    Hi Dietrich and Daniel,

    I’m considering using Grails and Vaadin for a new app I am developing. Can you provide any info on how to best perform data binding between Vaadin data model “items” and Grails domain objects?

    Or do you use Grails services?

    Many thanks,

    — Rodney

  3. Barton Hammond Reply

    Hi Dietrich

    Nice article.

    I am learning Vaadin now and am interested in seeing how you integrated PureMVC. Do you have source code available?

    Thanks in advance

    Barton

  4. Pingback: | Pathfinder Development | Software Developers | Blogs

  5. Tomasz Przybysz Reply

    Hi,

    I’m just exploring possibilities of using Grails + Vaadin. They seems to be really promising couple.
    However I don’t know what’s the exact usage of PureMVC. Probably because I don’t know it ;)

    I know I can’t use Grails MVC for Vaadin, but How can I use PureMVC and what for exactly?
    I would be good to avoid unnecessary layers as Grails domain classes used directly from Vaadin widgets allow really rapid app development.
    Where here is place for PureMVC, could you post some example (not necessary code)?

Leave a Reply

*

captcha *