Wednesday, July 28, 2010

Re: Views without presenters - how should they handle events?

Reference the presenter like explained in MVP part 2 :

  public interface MyPresenter extends Presenter {
    void onSave();
  }

  private MyPresenter presenter;

  @Override
  public  void setPresenter(MyPresenter presenter) {
    this.presenter = presenter;
  }

Then in your presenter, you implements MyPresenter and call in the constructor : setPresenter(this);

So final step :
 @UiHandler("inBoxBtn")
 void btnClicked(ClickEvent e) {
   presenter.onSave();
 }

And voilà ! This is something really easy to implements in an MVP framework like Gwt-Platform and it's even easier than the ActivityManager of Gwt !

Cheers,

On Wed, Jul 28, 2010 at 10:39 AM, xworker <blomqvist.andreas@gmail.com> wrote:
Hi

For now I'm putting events on the eventbus from the view. Then in the
entrypoint class handle all the events. I send the eventbus in the
constructor to the view since I have'nt put in GIN yet. I will look
into the new AcitvityManager concept from the 2010 IO and the
PlaceManager.

/A



On 28 Juli, 16:23, PeteUK <newbar...@gmail.com> wrote:
> Hello,
>
> I'm starting with GWT and struggling to know how I should architect my
> program.
>
> I am using the Mail application's source code as a basis for mine, so
> I'm hoping this reaches others who have inspected the source for the
> Mail application.
>
> Within the Shortcuts area, are three sub-areas (stacks in the
> StackLayoutPanel): Mailboxes, Tasks, and Contacts. Inside Mailboxes,
> assume I replaced the tree with a single button "In Box", and created
> an event handler for it:
>
> public class Mailboxes extends Composite {
>  ...
>
>  @UiHandler("inBoxBtn")
>   void btnClicked(ClickEvent e) {
>     // TODO: HOW TO HANDLE THIS??
>   }
>
> }
>
> I am not sure how to proceed in internally architecting the handling
> code. The Mailboxes class is a view but doesn't really have an
> associated presenter. I have an "outer presenter" which really deals
> with the entire outer view of the application (the root layout panel).
> I've been thinking about the following choices but not sure how to
> proceed:
>
> 1) I could put these events on the event bus, and dependency-inject
> the event bus into the Mailboxes instance somehow (I'm looking into
> gin/guice as a separate thing).
>
> 2) I could define a Presenter interface for Mailboxes which has a
> callback for this button. The Mailboxes class is a view class with no
> corresponding presenter class though, so not sure how I could
> implement this! The Mailboxes instance is created in Shortcuts.ui.xml
> as follows:
>
>     <g:stack>
>       <g:header size='3'>Mailboxes</g:header>     // .N.B style divs
> removed for brevity
>       <mail:Mailboxes ui:field='mailboxes'/>           // <---
> Mailboxes instance created here
>     </g:stack>
>
> 3) Define a Presenter interface for Mailboxes and implement the
> callback in the outer presenter object. This means outer presenter is
> dealing with things a lot lower in the object tree than I feel it
> should.
>
> If your task was to extend the Mail application in this way, how would
> you think it should be done?
>
> Thanks,
>
> Pete

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.




--
Christian Goudreau

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment