gpt4 book ai didi

java - 如何从ZK页面调用后端方法?

转载 作者:行者123 更新时间:2023-12-02 09:38:20 25 4
gpt4 key购买 nike

我想使用 onClick 方法动态生成图像以从页面调用。但无论我如何尝试,都失败了。

我在后端类中的代码如下:

public class RuleController  extends SelectorComposer<Component> {
.......
Image imageTemp = (Image)image.clone();
ZScript script = new ZScript("java","delCondition1("+indexCon1+")");
EventHandler evthdl = new EventHandler(script);
imageTemp.addEventHandler("onClick", evthdl);
........

public void delCondition1(int index){
.........
}
}

但是当我点击页面上的图像后,出现错误:

org.zkoss.zk.ui.UiException: Sourced file: inline evaluation of: ``delCondition1(0);'' : Command not found: delCondition1( int ) : at Line: 1 : in file: inline evaluation of: ``delCondition1(0);'' : delCondition1 ( 0 ) 

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.zkoss.lang.Classes.newInstance(Classes.java:76)
at org.zkoss.lang.Exceptions.wrap(Exceptions.java:163)
at org.zkoss.zk.ui.UiException$Aide.wrap(UiException.java:51)
at org.zkoss.zk.scripting.bsh.BSHInterpreter.exec(BSHInterpreter.java:136)
at org.zkoss.zk.scripting.util.GenericInterpreter.interpret(GenericInterpreter.java:342)
at org.zkoss.zk.ui.impl.PageImpl.interpret(PageImpl.java:970)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3135)
at org.zkoss.zk.ui.AbstractComponent.service(AbstractComponent.java:3089)
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:611)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doGet(DHtmlUpdateServlet.java:487)
at org.zkoss.zk.au.http.DHtmlUpdateServlet.doPost(DHtmlUpdateServlet.java:495)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
at org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:479)
at org.apache.catalina.valves.rewrite.RewriteValve.invoke(RewriteValve.java:479)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1110)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:785)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1425)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

似乎onClick触发的java代码找不到方法:delCondition1(int),为什么?如何设置调用的方法?

最佳答案

您不应在生产中使用 zscript,这仅适用于原型(prototype)设计。请参阅the statement来自ZK团队。

如果您的图像是在 ZUL 文件中定义的,只需在您的方法上使用 @Listen("onClick = #yourImageId") 注释即可。

如果您的图像是动态生成的,请使用 EventListeneronClick 事件添加到您的图像:

public class RuleController  extends SelectorComposer<Component> {

...

Image imageTemp = (Image)image.clone();

EventListener<Event> actionListener = new SerializableEventListener<Event>() {
private static final long serialVersionUID = 1L;

public void onEvent(Event event) throws Exception {
delCondition1(indexCon1);
}
};

imageTemp.addEventListener(Events.ON_CLICK, actionListener);

...

public void delCondition1(int index){
...
}
}

请参阅documentation .

关于java - 如何从ZK页面调用后端方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57323740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com