当我调用@Listen-onClick时,ZK框架关联的Textbox返回NullPointerException



我是ZK Framework的新手,我正在使用一个简单的登录表单。当用户单击按钮时,我会收集用户名/电子邮件和密码。

当我测试登录按钮时,会出现NullPointerException。我搞不清代码出了什么问题。你能帮我吗?

让我们看看应用程序文件!

查看:login.zul

<?page title="Login" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="Login" border="normal" apply="zk_auth.controller.LoginController">
<vlayout>
Email: <textbox id="EmailBox" type="email" constraint="no empty" />
Password: <textbox id="PasswordBox" type="password" constraint="no empty" />
</vlayout>
<button id="LoginButton" label="Login"/>
</window>
</zk>

控制器:LoginController.java

package zk_auth.controller;
/*Omitted imports for brevity.*/
public class LoginController extends SelectorComposer<Component>
{
@Wire("LoginButton")
private Button LoginButton;
@Wire
private Textbox EmailBox;
@Wire
private Textbox PasswordBox;
@Listen("onClick = button#LoginButton")
public void Login()
{
UserCredential User = new UserCredential(EmailBox.getValue(), PasswordBox.getValue());
Authentication Authenticator = new Authentication();
if(Authenticator.checkUserCredential(User))
Messagebox.show("Authenticated!");
else
Messagebox.show("Access denied!");
}
}

现在,当我单击登录按钮时,会出现NullPointerException,显示这个弹出窗口。

控制台日志

dic 06, 2018 10:17:26 AM org.zkoss.util.resource.ResourceCache$Info isValid
INFORMAZIONI: Source is changed: /login.zul
dic 06, 2018 10:17:35 AM org.zkoss.zk.ui.impl.UiEngineImpl handleError
GRAVE: 
java.lang.NullPointerException
at zk_auth.controller.LoginController.Login(LoginController.java:35)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.zkoss.zk.ui.select.Selectors$ComposerEventListener.onEvent(Selectors.java:686)
at org.zkoss.zk.ui.AbstractComponent.onEvent(AbstractComponent.java:3162)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3132)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3074)
at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:138)
at org.zkoss.zk.ui.impl.UiEngineImpl.processEvent(UiEngineImpl.java:1846)
at org.zkoss.zk.ui.impl.UiEngineImpl.process(UiEngineImpl.java:1618)
at org.zkoss.zk.ui.impl.UiEngineImpl.execUpdate(UiEngineImpl.java:1321)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.process(DHtmlUpdateServlet.java:606)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:482)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:490)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

无法真正弄清楚此代码出了什么问题。我只知道Login((函数发生了异常。

您需要使用annotation@Listen 替换您的代码片段

@Listen("onClick = button#LoginButton")

@Listen("onClick = #LoginButton")

相关内容

  • 没有找到相关文章

最新更新