Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3277874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:25:06+00:00 2026-05-17T19:25:06+00:00

I am learning GWT and i have read at multiple places that using MVP

  • 0

I am learning GWT and i have read at multiple places that using MVP architecture is best suitable to develop a GWT Application

I have also read that its easy to do testing using the MVP ARCH.Can somebody explain me why its easy to do testing using the MVP architecture.

Also i am working on a project using MVP and i find it very tedious to make the view connect to the data base.I mean i have to update my presenter,service,serviceAsync,servicImpl,Facades in order to make connection to database.

So can somebody provide me the essence of MVP for GWT?i would appreciate a couple of examples.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:25:07+00:00Added an answer on May 17, 2026 at 7:25 pm

    Separation between the presenter (which contains logic) and view (a dumb wrapper around UI controls) allows you to:

    • write unit tests for the presenters that can run without needing the corresponding environment (desktop, browser, GWT widgets)
    • reuse front-end logic without being tied to a particular set of widgets/UI framework

    The latter use case is rare, so let’s focus on the MVP model’s suitability for automated, programmatic testing. With a team of developers this often takes the form of a continuous build/test cycle using Hudson (or similar) on a headless server, where it’s not practical to open a web browser, create controls, etc. every time a test is run.

    Typical usage of MVP+GWT is that views implement an interface provided by the presenter, and often this interface is defined in terms of other generic interfaces. Here’s a very simple presenter that increments a numeric label when a button is clicked – note that instead of exposing the TextBox and Button directly, the view returns generic HasText and HasClickHandlers instances:

    public class ButtonClickPresenter {
        public interface View {
            HasText currentValue();
            HasClickHandlers incrementButton();
        }
    
        private final View myView;
        private int currentValue = 0;
    
        public ButtonClickPresenter(View myView) {
            this.myView = myView;
            this.myView.currentValue().setText("0");
    
            this.bind(); // for the sake of demonstration
        }
    
        public void bind() {
            this.myView.incrementButton.addClickHandler(
                @Override
                new ClickHandler() {
                    void onClick(ClickEvent event) {
                        currentValue ++;
                        myView.currentValue().setText(
                            Integer.toString(currentValue));
                    }
                });
        }
    }
    

    The “real” view returns UI widgets (created via UiBinder in this example):

    public class ButtonClickView implements ButtonClickPresenter.View {
        // ... skipped UiBinder initialisation ...
    
        @UiField Label currentValueLabel;
        @UiField Button incrementButton;
    
        @Override
        public HasText currentValue() {
            return currentValueLabel;
        }
    
        @Override
        public HasClickHandlers incrementButton() {
            return incrementButton;
        }
    
        // ... etc ...
    }
    

    whereas unit tests create a dummy implementation (or use Mockito, EasyMock, etc.) and thus don’t require any UI components:

    public class ButtonClickPresenterTest {
        ButtonClickPresenter presenter;
        ClickHandler currentHandler;
        String currentText;
    
        @Before
        public void setUp() {
            presenter = new ButtonClickPresenter(
                // dummy view - just stores label text in a String and
                // keeps track of the Presenter's click handler
                new ButtonClickPresenter.View() {
                    @Override
                    public HasText currentValue() {
                        return new HasText() {
                            @Override public String getText() { return currentText; }
                            @Override public void setText(String text) { currentText = text; }
                        };
                    }
    
                    @Override
                    public HasClickHandlers incrementButton() {
                        return new HasClickHandlers() {
                            @Override
                            public HandlerRegistration addClickHandler(ClickHandler handler) {
                                currentHandler = handler;
                            }
                        };
                    }
                });
        }
    
        @Test
        public void testIncrement() {
            // initial value
            assertEquals("0", currentText);
    
            // clicking the button should increment the number
            currentHandler.onClick(null);
            assertEquals("1", currentText);
        }
    }
    

    As for your next paragraph: your views shouldn’t be connecting to the database at all! The presenter should request data via Service/ServiceAsync (or an abstraction such as gwt-dispatch or gwt-platform), then call methods on the view to populate the UI.

    By the way, those last two links (along with gwt-presenter) are a good start if you’re looking for GWT MVP code samples – combined with Google GIN they provide frameworks for tying all this stuff together.

    Having said all that, I agree – the combination of GWT+MVP+Java can be hard work and extremely verbose (I’m glad I don’t have to work with it much these days). The alternative, though, is even less attractive: an untestable, unmaintainable ball of spaghetti…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started learning GWT. My question is pretty simple: If I create
I'm working on learning GWT (total newb) and have a question regarding the Visualiztion
Coming from PHP with some Java Struts 2.0 experience any tips/tricks on learning GWT?
I have just started learning Javascript and I am absolutely overwhelmed with the number
I have developed web applications using JSF (myfaces components). But in these days of
learning about loops (still a beginner) in VB.net. I have got the below code
In learning Core Animation, I learned very quickly that if you don't do it
Still learning lxml. I discovered that sometimes I cannot get to the text of
Still learning JSP Web Applications here. I have been doing this for a while
I`m learning programming languages. And I decide that I need to lear a new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.