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 6611563
In Process

The Archive Base Latest Questions

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

I’m trying to build a gwt widget with separated model, view and presenter. I’m

  • 0

I’m trying to build a gwt widget with separated model, view and presenter.

I’m using just one class for all of these components so far:

A compact example:

public class MyCellSelectableTable extends Composite {

   private WhatEverRepresentation selectedCell;

   public MyCellSelectableTable() {

      Grid myTable = new Grid(2,2);
      /*
       * Some code to realize a table with cell selection
       * ...
       */

     initWidget(myTable);
  }
}

In my appreciation the information “selectedCell” (and in my project many other data) should be stored in a separate model.
How can I implement this structurally correct, so it still is a widget but with an encapsulated mvp architecture?

  • 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-25T19:59:09+00:00Added an answer on May 25, 2026 at 7:59 pm

    In one of my projects I was asked to design a spinner item which is dressed to look good on a mobile web app. Then we realized we actually need another view for our spinner which is ‘thinner’ as well. So I have tried to aplly the MVP approach to my widget implementation which worked well for me. This one below is a very simple example not for production use just for the sake of demonstration

    Define a Presenter and a View interface as in MVP pattern. The point here is to make the view implementations dumb so they can be switched without a hassle. Note that Spinner is not actually a Widget but it implements IsWidget which means it will be treated like a widget but in fact we will be passing the reference of our view implementation.

    public class Spinner implements IsWidget, SpinnerPresenter{
        interface View{
            Widget asWidget();
            void stepUp(int step);
            void stepDown(int step);
            void setValue(int value);
            void setPixelSize(int width,int height);
        }   
        View view;
        int value;  
        public Spinner() {
            view = new SpinnerImpl(this);
            view.setValue(0);
        }   
        public int getValue() {
            return value;
        }   
        public void setValue(int value) {
            if (value == this.value)
                return;
            this.value = value;
            view.setValue(value);
        }
        public void setPixelSize(int width, int height){
            view.setPixelSize(width,height);
        }
        @Override
        public void downButtonClicked() {
            value--;
            view.stepDown(1);
        }
        @Override
        public void upButtonClicked() {
            value++;
            view.stepUp(1);
        }
        @Override
        public Widget asWidget() {
            return view.asWidget();
        }
    }
    

    And the view Implementation itself which implements the view interface defined in Spinner class. Notice how we delegate user events to Spinner class to be handled over the SpinnerPresenter interface.

    public class SpinnerImpl extends Composite implements Spinner.View{
        private TextBox txtBox;
        private Button upButton,downButton;
        private HorizontalPanel panel;
        private SpinnerPresenter presenter;
        public SpinnerImpl(SpinnerPresenter presenter){
            this.presenter = presenter;
            upButton = new Button("up");
            downButton = new Button("down");
    
            txtBox = new TextBox();
            txtBox.setEnabled(false);
    
            panel = new HorizontalPanel();
            panel.add(upButton);
            panel.add(txtBox);
            panel.add(downButton);
    
            addHandlers();
            initWidget(panel);      
        }   
        private void addHandlers() {
            upButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    presenter.upButtonClicked();
                }
            });
            downButton.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    presenter.downButtonClicked();
                }
            });     
        }
        @Override
        public void stepDown(int step) {
            txtBox.setValue(Integer.parseInt(txtBox.getValue())-1+"");
        }
        @Override
        public void stepUp(int step) {
            txtBox.setValue(Integer.parseInt(txtBox.getValue())+1+"");
        }
        @Override
        public void setValue(int value) {
            txtBox.setValue(0+"");
        }
    }
    

    SpinnerPresenter interface :

    public interface SpinnerPresenter {
        void upButtonClicked();
        void downButtonClicked();
    }
    

    Finally to add my widget to rootpanel. Notice I can add spinner class as if it was a widget

    Spinner s = new Spinner();
    RootPanel.get().add(s);
    

    Now if i wanted to change the way my spinner item looks, change orientation, maybe add a fancy animation for spinning etc, I need only to change my View Implementation. Last but not least when it comes to testing my widget this approach will help since I can easily mockup my view.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.