Note that there are some explanatory texts on larger screens.

plurals
  1. POScaling gwt's "Contacts" (sample project) AppController with MVP
    primarykey
    data
    text
    <p>I'm just learning GWT so I'm still trying to sort out all of its quirks and features. I'm reading through the example they give illustrating the MVP pattern, and I pretty much get it, except I'm wondering about one thing.</p> <p>The AppController they use implements the ValueChangeHandler interface and the onValueChange method is triggered when history changes. </p> <p>My problem is with this onValueChange in the AppController (i've included it below for anyone who hasn't seen the sample project). It's doing a string comparison on the history token sent in and instantiating the appropriate presenter to handle the action. This is all fine and dandy for the sample app with 3 actions, but how would one scale this to a real app with many more actions? </p> <p>Sticking to this pattern would lead to a pretty large/ugly <code>else if</code>, but I'm still too new to GWT (and java) to infer a better pattern for larger apps.</p> <p>Any help is greatly appreciated!</p> <pre><code>public class AppController implements Presenter, ValueChangeHandler&lt;String&gt; { ... public void onValueChange(ValueChangeEvent&lt;String&gt; event) { String token = event.getValue(); if (token != null) { Presenter presenter = null; if (token.equals("list")) { presenter = new ContactsPresenter(rpcService, eventBus, new ContactsView()); } else if (token.equals("add")) { presenter = new EditContactPresenter(rpcService, eventBus, new EditContactView()); } else if (token.equals("edit")) { presenter = new EditContactPresenter(rpcService, eventBus, new EditContactView()); } if (presenter != null) { presenter.go(container); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload