Gwt architecture: why use MVP, editors, RequestFactory, Gin, etc.?

I have been working on a GWT application for a year now, and we never felt the need to use any of these frameworks or tools.

So, I feel that we are probably missing out.

We are doing the code behind style.

Here is a simple example of how we create our code:

MyPanel.ui.xml:

<label ui:field="label"/> <g:TextBox ui:field="box"/> <g:Button ui:field="button"/> 

MyPanel.java:

 @UiField LabelElement label; @UiField TextBox box; @UiField Button button; MyBean myBean; Messages messages = GWT.create(Messages.class); MyServiceAsync myServiceAsync = GWT.create(MyService.class); ... protected void i18n() { label.setInnerText(messages.label()); button.setText(messages.button()); } ... @UiHandler("box") void box_onValueChange(ValueChangeEvent<String> event) { myBean.setText(event.getValue()); } @UiHandler("button") void button_onClick(ClickEvent event) { myServiceAsync.sendData(myBean, new AsyncCallback<MyResponse>() { @Override public void onSuccess(ReponseDispoBean result) { Window.alert(result.message()); } @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); } }); } 

To communicate between panels (parts of pages, each in its own class), we use a widget or eventbus to send custom events.

For navigation we use places / tokenizers / actions and historymapper

And for unit and functional tests we use gwt-test-utils

What is it. Therefore, I wonder: with what pain do these tools help? What is a good reason to use them?

thanks

+7
source share
4 answers

Editors and GIN will cope with template reduction.
For example, compare the same screen without and with the Editors.
And when I say that the GIN deals with template reduction, it is only if you are already using dependency injection (DI). If you are not using DI, then well, you probably should .

Like DI, MVP helps to create test code, in particular, on testing presentation logic (not necessarily business logic, not the user interface). For example, it really doesn’t matter how you show something, what matters is that you show the right thing at the right time. One example might be a mistake: it doesn't really matter if they are red at the top of the screen or next to the form field or in the tooltip in the form field, which then turns red; what matters is that you submit the correct set of errors at the right time for viewing. How can I replace or change (and ideally should also be tested), but the same thing.
MVP can also be great at creating multi-factor applications: if the screens can be quite similar between mobile, tablet and desktop computers, then you can use the same presenter with three different views (and where the DI shines!).

As for RequestFactory (RF), this is a different client-server protocol than GWT-RPC, with its own set of functions and limitations. Unless you have a problem with GWT-RPC, you should not switch (although I would recommend that you see what RF is). For me, the main feature of RF is that the protocol (based on JSON) is larger than the API: the classes on the client and server do not have to be the same if they are compatible enough so that the client and server understand each other (add a property, change int to double , etc.); this is a huge difference compared to GWT-RPC, where you will have an error even with very minor and subtle changes in your classes.

But in the end, if it does not break, do not correct it .

+13
source

MVP just separates the logic from the view code and helps run the test in jvm instead of the slow GWTTestcase.

Editors help you associate object properties with input fields. This causes the code to copy and paste the fields into your objects obsolete.

Gin helps connect your objects. Again, this makes testing easier. You can link your objects yourself, but why should you do this if the genie does this automatically for you?

RequestFactory is a replacement for RPC testing and is more data oriented. This helps you receive data in batch mode, which makes using DTO obsolete. You can use the RPC pen. But there are some disadvantages. You must create a Serverlet for each service or use the command template. This leads to the problem that you need to create an Action, Response and a processing service for the request itself. This is a lot of code to support.

+2
source

The only thing I could offer a look is RequestFactory vs gwt rpc. It does not require objects to be serializable and have quite a few performance improvements, such as sending only the difference by wire.

We also use a ClientFactory template that resembles a gin. We use this to enter the client class, depending on the type of device used (tablet, mobile phone, desktop).

+1
source

Your approach is fine. In fact, I started a lot of my prototype projects like this (instead of gwt-test-utils, for such projects I just use GWTTestCase). And you know, sometimes this is all that is needed, and everything else will only complicate it! Thus, this is not only good for prototypes, but can really work very well for some real projects.

But most often it turns out that I want to reuse some components and make them more customizable. And this is the time when I will reorganize MVP. And Jin, if I don’t have one yet (in fact, currently I usually start all projects with Jin).

So, you can add these things when you discover the need for them or a certain advantage (not because they are theoretically large, or “hips”).

By the way, I do not use the event bus approach (with the exception of small, well-defined sets of events), because the complexity of event systems usually explodes.

0
source

All Articles