我在 GWT 应用程序中创建了两个带有 UIBinder 的 java 类。我想借助在 EntryPoint 类中声明的通用方法将一个页面导航到另一个页面。
但是,我无法在 UIBinder 类的按钮单击事件上访问 EntryPoint 类的方法。
我的代码:
HelloUIBinder hb;
@UiField Button btnLogin;
public Test2() {
initWidget(uiBinder.createAndBindUi(this));
btnLogin.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
strEmail = txtEmail.getText().toString();
strPass = txtPass.getText().toString();
Window.alert(strEmail);
Window.alert(strPass);
hb.onLogin(strEmail, strPass);
}
});
}
在 HelloUIBinder 类中,
登录方法:
public void onLogin(String email, String pass)
{
Window.alert(email);
Window.alert(pass);
if(email == "abc@yahoo.com" && pass == "abc123")
{
RootPanel.get().clear();
tp = new TestPage();
RootPanel.get().add(tp);
animationHelper.goTo(tp, Animation.SLIDE);
}
else
{
Window.alert("Authentication Failed");
}
}
但是,虽然这种方法我收到 UmbrellaException 错误消息。如果我会在 UIBinder 类中编写相同的逻辑,那么它将可以正常进行条件检查。
现在我想通过使用类对象来使用来自不同类的方法。
有人知道吗?
请帮助解决从不同类调用方法的此错误。
提前致谢。