我现在正在检查我的代码以确保其正确且一致。我直接发现我以两种不同的方式加载 View : 一是:
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);
}
另一个是:
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);
}
它们似乎都可以工作,那么哪种是加载 View 的最佳/推荐方式?
最佳答案
您应该考虑在模型、 View 和演示者之间拆分代码。创建适当的图层。考虑使用 GIN 进行依赖注入(inject)。
阅读此处的文章:http://www.canoo.com/blog/2011/04/05/gwt-dependency-injection-recipes-using-gin/
关于java - 在 GWT Java 应用程序中加载 View /创建页面的正确方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35496857/