1

I have an application written in GWT. I want to be able to provide a subset of the same application for use when the site is opened in mobile browsers, and have been looking at mgwt as a way of achieving this.

The way I am expecting it to work is that I will augment my existing GWT application project with mgwt code (with some logic sharing) resulting in two entry points. My question is how to manage this given a single html page? I have seen the approach described in this article and was wondering whether that will work well with mgwt or whether there should be another pattern I should be considering?

Community
  • 1
  • 1
user3127996
  • 163
  • 1
  • 1
  • 7
  • This question is more suited for programmers.stackexchange.com . There you can ask "whiteboard questions" like this (things that you may be wondering while designing a program); Stack Exchange is more for questions where a particular piece of code is not working as expected. – logc Apr 12 '14 at 12:43

2 Answers2

1

I don't think you need 2 entry points. As kiran said above, you should reuse all the code except the view components. In case you used the GWT Activities and Places module, the view components should be completely decoupled from the rest of the code.

In this case you can use the the GWT.create method associated with the correct definitions in the module xml definition:

//in your entry point:

private IClientFactory clientFactory = GWT.create(IClientFactory.class);

//in your module xml definition:

 <replace-with class="com.vv.xui.client.DesktopClientFactory">
        <when-type-is class="com.vv.xui.client.IClientFactory" />
        <when-property-is name="formfactor" value="desktop"/>
  </replace-with>
    <replace-with class="com.vv.xui.client.MobileClientFactory">
        <when-type-is class="com.vv.xui.client.IClientFactory" />
        <when-property-is name="formfactor" value="mobile"/>
  </replace-with>

The form formfactor property can be defined as in this example: https://code.google.com/p/gwt-cx/source/browse/trunk/gwtcx/gwtcx-core/gwtcx-core-client/src/main/resources/com/gwtcx/FormFactor.gwt.xml

In your IClientFactory you will have something like this:

public interface IClientFactory {

    IHomeView getHomeView();
    ISearchView getSearchView();
    ...
}

Where IHomeView and ISearchView are the view interfaces implemented by the desktop and the mobile versions. In my case the View implementations are UiBinder components that implement the associated view interface.

In your DesktopClientFactory you will have something like this:

public class DesktopClientFactory implements IClientFactory {

private static final ISearchView searchView = new com.vv.xui.client.view.desktop.SearchView.SearchView();

    @Override
    public ISearchView getSearchView() {
        return searchView;
    }
...
}

In this way you don't need different entry points for mobile and desktop and can share all the code except the view components.

vlad_dd
  • 11
  • 1
0

That pattern in the link pointing to MobileWebApp on googlecode is correct. Basically you have UI view interfaces in GWT which stick to MVP pattern recommended on GWT. Then you can do different implementations of the UI Views based on the screen resolutions available. Obviously you don't want the same screen lay outs on desktop and mobile. So you will need to redesign your views for different form factors and then call the correct implementations based on the form factor the device. Since you already have a gwt application, you can create views for mobile using mgwt and reuse the code that you already created. But still you will have to create new views for mobile using mgwt, it wont be a straight forward replace.

kiran
  • 2,280
  • 2
  • 23
  • 30