FAQ

112 views
Skip to first unread message

plcoirier

unread,
Aug 11, 2009, 3:36:22 PM8/11/09
to Mvp4g
If you have other questions about the framework than the ones answered
in the FAQ or would like further information about a question, just
leave a message.

Suresh Reddy Guntaka

unread,
Aug 14, 2009, 6:09:10 AM8/14/09
to Mvp4g
can i use gxt(www.extjs.com) along with mvp4g if so can you please
guide me as to how to go about with it.

plcoirier

unread,
Aug 14, 2009, 4:24:13 PM8/14/09
to Mvp4g
On Aug 13, 5:39 pm, Yanick <yanick.roc...@gmail.com> wrote:
> "The first line creates a Java class thanks to the configuration file
> and a Generator."
> "For example, with the following configuration file:"
>
> How is that class generated from the configuration file? (Sorry to ask
> if it's obvious.)
The class is generated thanks to the Deferred Binding process (see
http://code.google.com/webtoolkit/doc/1.6/DevGuideCodingBasics.html#DevGuideDeferredBinding).
Inside the GWT configuration file of the Mvp4g module
(Mvp4gModule.gwt.xml inside the Mvp4g jar), you have the following
line:
<generate-with class="com.mvp4g.util.Mvp4gGenerator">
<when-type-assignable class="com.mvp4g.client.Mvp4gStarter" />
</generate-with>

This line indicates GWT compiler to call the generate method of the
Mvp4gGenerator class to create the Mvp4gStarter class when the
following code is compiled:
Mvp4gStarter starter = GWT.create(Mvp4gStarter.class);

The generate method of the Mvp4gGenerator (http://code.google.com/p/
mvp4g/source/browse/trunk/v1.0/src/src/com/mvp4g/util/
Mvp4gGenerator.java) is the starting point of the class generation if
you want to look into it.

> Will the argument of the generated Command always be named "form"? Can
> it be changed?
Yes it will always be "form" but it shouldn't impact your code. You
can name the way you want attribute of the handlers methods called by
the Command.

plcoirier

unread,
Aug 14, 2009, 7:22:01 PM8/14/09
to Mvp4g
Yes you can use gxt with mvp4g.
Compared to the available examples, the main difference will be that
your view will be built
using GXT panels and widgets instead of GWT ones.

You may have other impacts depending on the way you decide to go.

The first solution will be to also modify your view interface in order
them not to use basic GWT interfaces (like HasClickHandler,
HasValue..).
So instead of having view interface like:

GWTViewInterface{
public HasClickHandler getButton();
public HasValue<String> getField();
}

you will have:

GXTViewInterface{
public Button getButton();
public Field<String> getField();
}

In this case you will have an impact of your presenter (which should
be mininum). Only the call to presenter's view's method will be
different.
For example instead of having:

GWTPresenter extends Presenter<GWTViewInterface>{
...
public void bind(){
view.getButton().addClickHandler(new ClickHandler(){
...
});
}
...
}

you will have:

GXTPresenter extends Presenter<GXTViewInterface>{
...
public void bind(){
view.getButton().addSelectionHandler(new SelectionHandler(){
...
});
}
...
}

The logic of your presenter should stay the same whatever library
you're using.

You could also decide not to impact the view interface (and keep
defining them using basic GWT interface) and
create widgets that extends GXT and implements GWT interface.

For example, you can have

MyTextInput extends TextField implements HasValue<String>{

}

The second way is probably the best way to go. You may have some extra
classes to create but if you want to switch Widget library, only your
view will be impacted (not your presenter) so that you can easily
switch.

When I have time (it might not be before the end of the month), I will
try to implement the simple example with GXT in order how to give you
an idea on how to do it.

On Aug 14, 12:09 pm, Suresh Reddy Guntaka <sureshredd...@gmail.com>
wrote:

plcoirier

unread,
Sep 14, 2009, 5:02:17 PM9/14/09
to Mvp4g
An example with GXT and Mvp4g is available. I created a new post about
it (see http://groups.google.com/group/mvp4g/browse_thread/thread/5ba8664afbbda1f7).
> > guide me as to how to go about with it.- Hide quoted text -
>
> - Show quoted text -

dario.p...@gmail.com

unread,
Feb 13, 2015, 5:21:36 AM2/13/15
to mv...@googlegroups.com
Hi Pierre,
I'm new to gwt and I'm writing a new application based on your framework.

Probably you discussed my problem inside your WIKI, but I didn't find the answers I'm looking for.

The problem:

I've a LazyPresenter impl; its view (a LazyView) performs some work and to do it the user have to perform several operation altering the initial state, including compiling form.

At the end of all I want to recreate the view for a new operation, but calling getPresenter().createView() I receive a IllegalState Exception.

Please, can you tell me what I have to do?

Thank you in advance for your attention.


Message has been deleted

Frank Hossfeld

unread,
Feb 13, 2015, 6:55:33 AM2/13/15
to mv...@googlegroups.com

Hi Dario,

sorry, I did not saw, that you mean the createView method of your presenter. I was thinking about the createView method of the view class which is used by the LazyView interface. Can you provide an example or more information?

Frank

dario.p...@gmail.com

unread,
Feb 13, 2015, 8:53:21 AM2/13/15
to mv...@googlegroups.com
Hi Frank,
Thanks for your help.
Here it is some snippet of code:

//----------
// EventBus
//----------
@Events( startPresenter = RootPresenter.class, historyOnStart = true )
public interface BookingPlaceServiceEventBus extends EventBusWithLookup {

    @Start
    @Event( //handlers = { DatiViaggioWidgetPresenter.class },
            bind = { LegendaWidgetPresenter.class, DisponibilitaPartenzeWidgetPresenter.class, HeaderPresenter.class, FooterPresenter.class }  )
    void start();

    @InitHistory
    @Event( handlers = RootPresenter.class )
    void init();

    @Event( handlers = EmissioneCarnetPresenter.class, bind = { IntestatarioWidgetPresenter.class, FatturaWidgetPresenter.class, CarrelloWidgetPresenter.class, CarnetGridWidgetPresenter.class } )
    void showEmissioneCarnet();

    @Event( handlers = RootPresenter.class )
    void exit();

    ...
}

//---------------
// Root Presenter
//---------------
@Presenter( view = RootView.class )
public class RootPresenter extends BasePresenter<IRootView, BookingPlaceServiceEventBus> implements IRootPresenter {

    public void onSetBody( IsWidget body ) {
        view.setBody( body );
    }

    public void onInit() {
        eventBus.showEmissioneCarnet();
    }

    ...
   
}

@Presenter(view = EmissioneCarnetView.class)
public class EmissioneCarnetPresenter extends LazyPresenter<IEmissioneCarnetView, BookingPlaceServiceEventBus> implements IEmissioneCarnetPresenter {
   
    @Inject
    CarrelloWidget carrelloWidget;
   
    @Override
    public void onShowEmissioneCarnet() {
       
        eventBus.clearEast();
        eventBus.addEast(carrelloWidget, true);
       
        eventBus.clearWest();

        eventBus.setBody( view );

    }

    @Override
    public void onExit() {
        eventBus.exit();
    }
}

The flow:
1) When the application starts RootPresenter calls eventBus.showEmissioneCarnet();
2) EmissioneCarnetView is shown as new
3) User alter the EmissioneCarnetView's state (UI and internal state) and confirm the operation
4) Here's the problem: EmissioneCarnetView calls getPresenter().onShowEmissioneCarnet() to start a new operation (the same event called in 1 above) but the view is not created (renewed) and the previous choices persist. I'd have to reset by hand.



Frank Hossfeld

unread,
Feb 15, 2015, 3:42:53 AM2/15/15
to mv...@googlegroups.com
Hi Dario,

the mvp4g framework is designed to have a small footprint. When you start your application  mvp4g will create all presenter and views.
To avoid creating the DOM elements at start up, mvp4g offers the LazyView implementation. 

Once a view is created, it will always be reused. That means, showing a view again, it will display all the data from the last time.

But, before I will answer one more question:

Your EmissioneCarnetView, is it the content area of your application? For example, if someone clicks in the navigation and goes to another view, the content of the EmissioneCarbetView changes?

If yes, you should check your RootView. THen you need more presenters and views.

In your case, to change the view, you have two opportunities:

First, you can use a method in the view to recreate the view when needed, second you can use the  multiple presenter feature. Using this feature you can create new presenter and view pairs, and the presenter to the events and the view is new one. But be careful. Using this feature, you have to remove the presenters from the eventbus.

In your case using a recreate method inside the view would be the best choice.

Frank 

dario.p...@gmail.com

unread,
Feb 16, 2015, 3:56:15 AM2/16/15
to mv...@googlegroups.com
Hi Frank,
EmissioneCarnetView is not the content area of my application: RootView is.

Indeed EmissioneCarnetPresenter.onShowEmissioneCarnet() calls eventBus.setBody( view ) and this is the code in eventbus:

    @Event( handlers = RootPresenter.class )
    void setBody( IsWidget body );

My EmissioneCarnetView includes other nested widgets. One of them is FatturaWidget declared in EmissioneCarnetView as follow:

    @Inject
    @UiField(provided=true)
    @Ignore
    @Path("fattura")
    FatturaWidget fatturaWidget;

This is FatturaWidget (a LazyView)

@Singleton
public class FatturaWidget extends ReverseCompositeView<IFatturaPresenter> implements IFatturaWidget, Editor<FatturaBean>, IInputTextFieldParent {
...
}

This is IFatturaWidget

public interface IFatturaWidget extends IsWidget, LazyView {
...
}


How do I  have to change EmissioneCarnetView.creatView()? How can I instantiate FatturaWidget (or other LazyView) on demand?

Note that if I remove @Singleton annotation
I recieve the fooolwing error:
com.google.gwt.event.shared.UmbrellaException: Exception caught: This UIObject's element is not set; you may be missing a call to either Composite.initWidget() or UIObject.setElement()

Why?

Thank for your help,
    Dario
 

Frank Hossfeld

unread,
Feb 16, 2015, 9:23:08 AM2/16/15
to mv...@googlegroups.com
Hi Dario,

I am not sure if I understand you correct.

I expect that you have something like a shell (your root view). This shell has several areas to show widgets. For example an header area to show a header widget, a navigation area to show the navigation, a area where the widgets change depending on the selection of your navigation or other widgets currently display in the body area.

All this widgets are presenter/view pairs. If you want to change the widget in your content area, fire an event, that is catcht by a presenter and this presenter fires the setBody event with his view again. 

That’s the way it should work.

Presenter should never reference a widget (as your EmissioneCarnetPresenter does). Widgets are located inside the views. Views will be created when the presenters are created. Once a view is created, it stays until the application stops.

If you want to change something inside the view use removeFromParent and add. 

So, why are you trying to create a new view?

Btw, the exception means, that you did not call the initWidget-method to set the element of your composite.

I have uploaded a small demo project that shows how to deal with changing the body:


Hope that helps.

Frank

dario.p...@gmail.com

unread,
Feb 17, 2015, 6:36:33 AM2/17/15
to mv...@googlegroups.com
Hi Frank,
You understood.

My RootView is an empty widget with 3 columns:
  • west (on the left).
  • body (on the center and the main content area)
  • east (on the right) 

My EmissioneCarnetView has to been shown in the body, for this I
  1. call eventBus.eventBus.showEmissioneCarnet() -> handled by EmissioneCarnetPresenter
  2. EmissioneCarnetPresenter calls eventBus.setBody( view ) -> handled by RootPresenter
  3. RootPresenter calls RootView.setBody that at least shows my EmissioneCarnetView
And this works fine.

But I also want to show CarrelloWidget on the right column of RootView (and if necessary other widget ie a Legend widget).
To do this EmissioneCarnetPresenter calls eventBus.addEast( carrelloWidget ).

If I understand your thought, I'd have to call eventBus.addCarrelloWidget() (if necessary eventBus.addLegendWidget()). This events have to be handled by RootPresenter who calls RoortView.addCarrelloWidget(CarrelloView). But how can I instantiate CarrelloWidget, CarrelloPresenter and bind both each other?

And if in an other logic view I have to reinstantiate my CarrelloWidget?

I need to rebuild my view to reset it's internal state as it was build as the firszt time. Suppose the first time the view has
  1. read some info from db to populate a ListBox the user has to choose a value from
  2. opened a disclosure panel to collect some customer info
  3. validated customer info
  4. depending on user choice, opened another disclosure to collect VAT info
  5. complete the work
Now, suppose the user has to repeat all the operations described above for another customer, how can I start once again as nothing has happened before?

Just another question, can I have multiple LazyPresenter or they have to be BasePresenter?

Please help.

P.S. I tried to open the link for your demo project but I get the error

Error (404)

We can't find the page you're looking for. Check out our Help Center and forums for help, or head back to home.

Frank Hossfeld

unread,
Feb 17, 2015, 4:27:00 PM2/17/15
to mv...@googlegroups.com
Hi Dario,

I have corrected the download link. Now, it should work. 

First, let me answer your question. Yes, you can have several LazyPeresenters. LazyPresenter indicates that the presenter has a createPresener method which is called when the presenter needs to be build, nothing more.

mvp4g creates a view as singleton. Once it is created, you have to reset the view if you reuse the view. For example, if you have a client detail view in your application, the same view ist used to display the data of customer A and customer B.

Frank
Reply all
Reply to author
Forward
0 new messages