PureMVC

16 views
Skip to first unread message

marcelo melo

unread,
Oct 23, 2008, 7:48:48 AM10/23/08
to google-we...@googlegroups.com
Hi, is anyone using PureMVC for Java / GWT?

Thanks

Flemming Boller

unread,
Oct 23, 2008, 7:53:57 AM10/23/08
to Google-We...@googlegroups.com
Yes I am.  I think is it rather nice little MVC implementation, which has made it more easy for us to make
components talk to each other in a loosely coupled way.

Minus is however, that it easy also to create a spider web of notifications that is hard to overview.

But common sense and "keep it simple" should be used here :-)


/Flemming

marcelo melo

unread,
Oct 23, 2008, 8:11:31 AM10/23/08
to Google-We...@googlegroups.com
Totally agree with you... Simplicity is key most of the times (at
least it should :) ).

I have one question that is really annoying me. Having used it
(puremv) with Flex, it is easy to fire an event at the View and
associate it with a method at the Mediator. But, how to deal with it
on GWT? I am adding the Mediator as the event listener of the View (by
making it implement the relevant View listeners - ClickListener,
etc.), but I'm not quite sure if it's the best way to do it...

Any ideas?

Thanks!

Flemming Boller

unread,
Oct 23, 2008, 11:06:31 AM10/23/08
to Google-We...@googlegroups.com
Hi
We have done it like the mediator has a reference to the view (which implements a gwt- neutral interface).

The View has a "hard reference" the mediator.

We want the mediator to be "unaware" of GWT because that means we are able to perform many junit tests of the "gui"
without using the GETTestCase....which is a "no-go" Testcase :-)


Please let me hear how you progress and the experiences you have with puremvc....

/FLeming

yunhui song

unread,
Oct 23, 2008, 1:09:22 PM10/23/08
to Google-We...@googlegroups.com
Hi

   I have used Guice and Gin to implements MVC framework(like backend spring framework). By this way view(ui), event Listener and data access(xmlHttpReqeust wrapped by REST-GWT) can be seperated by three layers.

   Gin module used to initialize and couple all the instance used in the GWT module. It's a typicall Ioc container. I found it is rocking by this way in my project.

Sammi
--
Best Regards,
Sammi

Ed

unread,
Oct 24, 2008, 4:35:29 AM10/24/08
to Google Web Toolkit
Have a look at mygwt (call gxt now). They use a nice MVC
implementation.

-- Ed

On Oct 23, 7:09 pm, "yunhui song" <songyunhui2...@gmail.com> wrote:
> Hi
>
> I have used Guice and Gin to implements MVC framework(like backend spring
> framework). By this way view(ui), event Listener and data
> access(xmlHttpReqeust wrapped by REST-GWT) can be seperated by three layers.
>
> Gin module used to initialize and couple all the instance used in the GWT
> module. It's a typicall Ioc container. I found it is rocking by this way in
> my project.
>
> Sammi
>
> On Thu, Oct 23, 2008 at 8:06 AM, Flemming Boller
> <flemming.bol...@gmail.com>wrote:
>
>
>
> > Hi
> > We have done it like the mediator has a reference to the view (which
> > implements a gwt- neutral interface).
>
> > The View has a "hard reference" the mediator.
>
> > We want the mediator to be "unaware" of GWT because that means we are able
> > to perform many junit tests of the "gui"
> > without using the GETTestCase....which is a "no-go" Testcase :-)
>
> > Please let me hear how you progress and the experiences you have with
> > puremvc....
>
> > /FLeming
>
> > On Thu, Oct 23, 2008 at 2:11 PM, marcelo melo <marcelotm...@gmail.com>wrote:
>
> >> Totally agree with you... Simplicity is key most of the times (at
> >> least it should :) ).
>
> >> I have one question that is really annoying me. Having used it
> >> (puremv) with Flex, it is easy to fire an event at the View and
> >> associate it with a method at the Mediator. But, how to deal with it
> >> on GWT? I am adding the Mediator as the event listener of the View (by
> >> making it implement the relevant View listeners - ClickListener,
> >> etc.), but I'm not quite sure if it's the best way to do it...
>
> >> Any ideas?
>
> >> Thanks!
>
> >> On Thu, Oct 23, 2008 at 9:53 AM, Flemming Boller
> >> <flemming.bol...@gmail.com> wrote:
> >> > Yes I am. I think is it rather nice little MVC implementation, which
> >> has
> >> > made it more easy for us to make
> >> > components talk to each other in a loosely coupled way.
>
> >> > Minus is however, that it easy also to create a spider web of
> >> notifications
> >> > that is hard to overview.
>
> >> > But common sense and "keep it simple" should be used here :-)
>
> >> > /Flemming
>
> >> > On Thu, Oct 23, 2008 at 1:48 PM, marcelo melo <marcelotm...@gmail.com>

Matthieu

unread,
Oct 24, 2008, 4:46:19 AM10/24/08
to Google Web Toolkit
Hi,

>>>Flemming Boller
We used Gwt only component too.
Our mediator give this components a 'Gwt ClickListener' wich send
Pure Notification.

Matthieu.

Thomas Broyer

unread,
Oct 24, 2008, 6:39:40 AM10/24/08
to Google Web Toolkit

On 23 oct, 19:09, "yunhui song" <songyunhui2...@gmail.com> wrote:
> Hi
>
>    I have used Guice and Gin to implements MVC framework(like backend spring
> framework). By this way view(ui), event Listener and data
> access(xmlHttpReqeust wrapped by REST-GWT) can be seperated by three layers.
>
>    Gin module used to initialize and couple all the instance used in the GWT
> module. It's a typicall Ioc container. I found it is rocking by this way in
> my project.

I'm curious how you're binding event listeners using Gin.
Would you mind sharing some code?

marcelo melo

unread,
Oct 24, 2008, 6:57:48 AM10/24/08
to Google-We...@googlegroups.com
Ok, that sounds like a good idea, especially concerning unit testing.
I was avoiding to couple the View with the Mediator, but now your
advice makes sense to mee.

Thanks!

yunhui song

unread,
Oct 26, 2008, 7:09:49 PM10/26/08
to Google-We...@googlegroups.com

Hi,

  Actually, Gin is used to implements Ioc Container. It can bind everything not only event Listener.

  Guice or Spring can do that naturally, but because GWT can not support Java reflection, such as forClass("className").getInstance. So Gin use generic and annotation to do that.

  I have a open source project to do that.  GinModule and GindInjector are key players for that.
  please check out here, that's a real world project.

Enjoys,
Sammi

Thomas Broyer

unread,
Oct 26, 2008, 9:50:07 PM10/26/08
to Google Web Toolkit

On 27 oct, 00:09, "yunhui song" <songyunhui2...@gmail.com> wrote:
> Hi,
>
>   Actually, Gin is used to implements Ioc Container. It can bind everything
> not only event Listener.
>
>   Guice or Spring can do that naturally, but because GWT can not support
> Java reflection, such as forClass("className").getInstance. So Gin use
> generic and annotation to do that.

Sorry, I should have been clearer: I know what Guice (and Gin) and
Spring are. Just that they cannot AFAIK inject listeners (i.e. call
some addXListener method, eventually several times on a single
instance). Of course you can use method injection with a
setXListeners(List<XListener>) method (should be supported by Gin as
of today) but I wouldn't call it "injecting event listeners"; or
inject event sources or event targets but that's not flexible at all
(why having "event listeners" in this case, just keep references to
the injected widgets and call the appropriate methods on them)

>   I have a open source project to do that.  GinModule and GindInjector are
> key players for that.
>   please check out here, that's a real world project.
>    http://openorg.googlecode.com/svn/trunk/magpie

I've seen some widgets be injected other widgets but not a single
event listener (or I missed something).

yunhui song

unread,
Oct 26, 2008, 11:26:48 PM10/26/08
to Google-We...@googlegroups.com
Hi Thomas,

    I've seen some widgets be injected other widgets but not a single
event listener (or I missed something).

It's true that for my project I only injected some widgets on a main panel.  That's the project specific choice. Because it's more easy to do that.

I'am not very clear your use case now. Let me have a guess for the use case:

1. We have two widgets w1 and w2, both of them would fire Event clickEvent.

2. We need one Event Listener named CommonEventListener, we expect it can be used to process clickEvent fired from both w1 and w2.

3. We hope the container, that is Gin to inject when system initialize. So refractor the code like.
    W1 w1 = new W1();
    w1.addClickEventListener(new CommonEventListener(p1,p2){});

    W2 w2 = new W2();
    w2.addClickEventListener(new CommonEventListener(p1,p2){});
by:

  CommonEventListener aCommonEventListener = injector.getCommonEventListener();
  W1 w1 = injector.getW1();
  w1.addClickEventListener(aCommonEventListener);
  W2 w2 = injector.getW2();
  w2.addClickEventListener(aCommonEventListener);

Because polymorphism is not usable in GWT, we can not use W1 or W2's common interface or base class as CommonEventListener. My suggestion is:

private W1 w1;
private W2 w2;
@inject 
public CommonEventListener(W1 w1,W2 w2){
   //w1 and w2 should be created by ginmodule as singleton instance.
   this.w1 = w1;
   this.w2 = w2;
}

public void onClick(Event e){
   if(e.getSource() == w1){
      //w1.update();
   }else if(e.getSource() == w2){
      //w2.update();
   }
}

I don't think it's an perfect solution(you must change the parameter, as you said, use List<T> is same like ). But it should be able to manage the listener and ui creation by container and unit test could be implemented easily.

Hope that is not confusing. 

Sammi








Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages