我已经关注了GWTP教程的GettingStarted
http://code.google.com/p/gwt-platform/wiki/GettingStarted
但遗憾的是处理程序无法正常工作,getUiHandlers()返回null,异常堆栈跟踪与以下内容相同:
How to use UiHandlers of GWT Platform?
查看课程
public class AView extends ViewWithUiHandlers<AUiHandlers> implements APresenter.Display {
@UiTemplate("AView.ui.xml")
interface AViewUiBinder extends UiBinder<Widget, AView> {}
private static AViewUiBinder uiBinder = GWT.create(AViewUiBinder.class);
@UiField Button saveBtn;
@UiField Button cancelBtn;
@UiField DivElement errorDiv;
private Widget widget;
@Inject
public AssetView() {
widget = uiBinder.createAndBindUi(this);
}
public Widget asWidget() {
return widget;
}
// Implementation: Presenter's Display methods
public void setErrorDivText(String msg) {
errorDiv.getStyle().setDisplay(Display.BLOCK);
errorDiv.setInnerText(msg);
}
// Handlers
@UiHandler("saveBtn")
void onSaveButtonClick(ClickEvent event) {
if(getUiHandlers() != null) {
getUiHandlers().onSaveButtonClick();
}
}
@UiHandler("cancelBtn")
void onCancelButtonClick(ClickEvent event) {
if(getUiHandlers() != null) {
getUiHandlers().onCancelButtonClick();
}
}
}
处理程序界面
public interface AUiHandlers extends UiHandlers {
void onSaveButtonClick();
void onCancelButtonClick();
}
演示
public class APresenter extends Presenter<APresenter.Display, APresenter.AssetProxy> implements AUiHandlers {
public interface Display extends View, HasUiHandlers<AUiHandlers> {
public void setErrorDivText(String msg);
}
@ProxyStandard
@NameToken(NameTokens.ASSET)
public interface AssetProxy extends ProxyPlace<AssetPresenter> {}
@Inject
public AssetPresenter(EventBus eventBus, Display view, AssetProxy proxy) {
super(eventBus, view, proxy);
getView().setUiHandlers(this);
}
@Override
protected void onBind() {
super.onBind();
}
@Override
protected void revealInParent() {
RevealRootContentEvent.fire( this, this );
}
public void onSaveButtonClick() {
getView().setErrorDivText("Save clicked.");
}
public void onCancelButtonClick() {
getView().setErrorDivText("Cancel clicked.");
}
}
无法理解我犯错误的地方,关于UiHandlers的实现与上述教程链接中的说明相同。
答案 0 :(得分:0)
UiHandlers is not generic; it cannot be parameterized with arguments
当我看到你的处理程序界面时,你已经通过了AUiHandlers类型。我不明白UiHandlers的包结构。它应该是 com.gwtplatform.mvp.client.UiHandlers 。
请检查它的导入。
<强>更新强>
删除private static AViewUiBinder uiBinder = GWT.create(AViewUiBinder.class);
并传递为构造函数参数
@Inject
public AssetView(AViewUiBinder uiBinder) {
widget = uiBinder.createAndBindUi(this);
}