|
#1
|
|||
|
|||
|
Hello,
the model view presenter pattern in combination with gwt, which was presented on the google i/o (http://code.google.com/intl/de-DE/ev...ractices.html), doesn't seem to work with Interfaces of smartgwt. if I try to add a Listener on a smartgwt specific handler (eg a cellclickhandler for a listgrid) in the presenter, it seems to be completely ignored. a sample application of how to use mvp in gwt can be found here: http://code.google.com/p/gwt-mvp-sample/ a concrete example: in the presenter I define an interface: Code:
public class Presenter {
interface Display {
HasCellClickHandlers getFoo();
}
}
Code:
public HasCellClickHandlers getFoo() {
return thelistgrid;
}
Code:
public void bindView(final Display view){
this.view = view;
view.getFoo().addCellClickHandler(new CellClickHandler() {
public void onCellClick(CellClickEvent event) {
// do something
}
});
does anyone know how to fix this? Are those interfaces not supported in smartGWT? will they be supported in future? best regards and thank you for your help, mat Last edited by mat.dinister; 12th Aug 2009 at 01:17.. |
|
#2
|
|||
|
|||
|
There's nothing special required to support MVP. The SmartGWT ListGrid cell handlers work just fine and the MVP simply making the appropriate calls to SmartGWT.
Have a look at this Cell Click sample. If you're still having issues, post a simplified standalone testcase that demonstrates the issue. Sanjiv |
|
#3
|
|||
|
|||
|
thanks for your answer, but I still have issues with smartgwt and mvp (I am already working with smartgwt 1.2).
I prepared a simple demonstration: MvpView.java Code:
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.events.HasCellClickHandlers;
public class MvpView extends Composite implements MvpPresenter.Display {
private final ListGrid countryGrid = new ListGrid();
private Button myButton = new Button("save");
public MvpView() {
countryGrid.setAlternateRecordStyles(true);
countryGrid.setShowAllRecords(true);
ListGridField nameField = new ListGridField("countryName", "Country");
ListGridField capitalField = new ListGridField("capital", "Capital");
ListGridField continentField = new ListGridField("continent", "Continent");
countryGrid.setFields(nameField, capitalField, continentField);
countryGrid.setData(CountryData.getRecords());
// works here but has to be in the presenter (mvp pattern)
// countryGrid.addCellClickHandler(new CellClickHandler() {
// public void onCellClick(CellClickEvent event) {
// GWT.log("oncellclick listgrid sucessful here but should be in the presenter!", null);
// }
// });
RootPanel.get().add(countryGrid);
RootPanel.get().add(myButton);
}
public HasCellClickHandlers getListGridCellClick() {
return countryGrid;
}
public HasClickHandlers getMyButton() {
return myButton;
}
}
Code:
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.smartgwt.client.widgets.grid.events.CellClickEvent;
import com.smartgwt.client.widgets.grid.events.CellClickHandler;
import com.smartgwt.client.widgets.grid.events.HasCellClickHandlers;
public class MvpPresenter {
interface Display {
HasClickHandlers getMyButton();
HasCellClickHandlers getListGridCellClick();
}
private Display view;
public void bindView(final Display view) {
this.view=view;
view.getMyButton().addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
GWT.log("onclick button sucessful", null);
}
});
view.getListGridCellClick().addCellClickHandler(new CellClickHandler() {
public void onCellClick(CellClickEvent event) {
GWT.log("oncellclick listgrid sucessful", null);
}
});
}
}
Code:
public void onModuleLoad() {
presenter.bindView(view);
}
The problem is, still, that the CellClickHandler is ignored in the presenter, but would work in the view directly. any suggestions? |
|
#4
|
|||
|
|||
|
the related ticket on the issue tracker can be found here:
http://code.google.com/p/smartgwt/is...ary%20Reporter |
|
#5
|
|||
|
|||
|
Hi All
For mvp concepts i created some several classes which are implemented HasClickHandlers This is stub for IButton Code:
import ClickHandlerImpl;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
public class IButton extends com.smartgwt.client.widgets.IButton implements HasClickHandlers {
public HandlerRegistration addClickHandler(ClickHandler clickHandler) {
return super.addClickHandler(new ClickHandlerImpl(clickHandler));
}
}
Code:
public class ClickEventImpl extends ClickEvent {
}
Code:
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
public class Presenter {
public interface Display {
HasClickHandlers getTestButton();
}
public void bindDisplay(Display d) {
d.getTestButton().addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
// do something
}
});
}
}
Code:
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.RootPanel;
public class View implements Presenter.Display {
private IButton testButton;
public View() {
testButton = new IButton("Test");
RootPanel.get().add(testButton);
}
public HasClickHandlers getTestButton() {
return testButton;
}
}
Likely you can implement HasValue<T>, HasSelectionHandlers<T>, ect. I hope GmartGWT team will implement GWT Has... interfaces in their components. Thanks |
|
#6
|
|||
|
|||
|
gavrikvetal,
I'm not sure what you're trying to do here? The SmartGWT components do implement various handlers and there's absolutely no need to adapt the IButton's HasClickHandlers with com.google.gwt.event.dom.client.HasClickHandlers. You can implement MVP with any *Handler as illustrated in mat.dinister's sample. Sanjiv |
|
#7
|
|||
|
|||
|
Hi Sjivan,
I'm currently working on a gwt app that we are porting over to smartgwt and I'm experiencing the same problems when trying to use the MVP pattern with an itemButton. if I add a listener directly to the button an event is fired but if i had a listener in my presenter class it is ignored. I've read above that you have fixed this problem and was wondering if you could direct me to the fix or the patch. regards Naim |
|
#8
|
|||
|
|||
|
The issue mat.dinister posted was resolved in SVN. Can you try running using the latest build from SVN from here : http://www.smartclient.com/smartgwt/builds/
If you're still having issues, please post a standalone testcase. Note that I'm planning on releasing SmartGWT 1.2.1 which incorporates some minor bugfixes and module refactoring pretty soon (perhaps this weekend). Sanjiv |
|
#9
|
|||
|
|||
|
Hi Sjivan,
Thanks for the quick response I'm now currently using the latest build and the issue seems to be resolved thanks again . |
|
#10
|
|||
|
|||
|
I checked 1.3 and I do not see a way to represent a DynamicForm, a Grid, a TextItem, etc., as a single interface in the Presenter. It seems to be that you still need to create custom interfaces - and derived types of these SmartGWT componentes that implement these interfaces -.
Has anybody using the MVP pattern found a better way? To clarify, in MVP you do not want the implementation classes (such as DynamicForm) to appear in the Presenter - they should just be present on the View -. O/w you cannot create standard JUnit cases (you have to use GWTTestCase). Thus, you need interfaces that can be used to replace these components in the Presenter. I would go further and state that SmartGWT - as a project based on GWT -should try to follow/implement as much as possible the same interfaces that GWT defines. That way, we can be sure that in the future any changes/improvements to GWT will not imply a huge refactoring for SmartGWT....nor for our projects based on SmartGWT. Thanks Last edited by netname; 28th Sep 2009 at 08:38.. |