Reputation: 2005
I am now going through my code to ensure it is correct and consistent. Straight way I find that I load a view in two different ways: One is:
public HikeRecordView() {
//On load of page get the stored view data and create the page
verticalPanel.addAttachHandler(new Handler() {
public void onAttachOrDetach(AttachEvent event) {
if (event.isAttached()) {
rpc = (DBConnectionAsync) GWT.create(DBConnection.class);
ServiceDefTarget target = (ServiceDefTarget) rpc;
String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection";
target.setServiceEntryPoint(moduleRelativeURL);
horizontalPanel_Existing.clear();
verticalPanel.clear();
AsyncCallback<ViewData> callback = new ViewDataHandler<ViewData>(HikeRecordView.this);
rpc.getViewData(callback);
}
}
});
initWidget(verticalPanel);
}
And the other is:
public PackHolidayView() {
rpc = (DBConnectionAsync) GWT.create(DBConnection.class);
ServiceDefTarget target = (ServiceDefTarget) rpc;
String moduleRelativeURL = GWT.getModuleBaseURL() + "MySQLConnection";
target.setServiceEntryPoint(moduleRelativeURL);
//On load of page render the page
verticalPanel.addAttachHandler(new Handler() {
public void onAttachOrDetach(AttachEvent event) {
verticalPanel.clear();
verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
//On load of page get the Account Level and ID of the account holder.
AsyncCallback<ViewData> callback = new ViewDataHandler<ViewData>(PackHolidayView.this);
rpc.getViewData(callback);
}
});
initWidget(verticalPanel);
}
They both seem to work so which is the best/recommended way to load a view please?
Upvotes: 0
Views: 102
Reputation: 802
You should think about splitting the code between Model, View and Presenter. Create appropriate layers. Consider using GIN for Dependency Injection.
Read an article located here: http://www.canoo.com/blog/2011/04/05/gwt-dependency-injection-recipes-using-gin/
Upvotes: 1