Q:

How to call backend method from ZK page?

I want to dynamically generate image with onClick method to call from page. But no matter how I tried, it goes failed.
My code in the backend class is like:
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){
      .........
   }
}

but after I Clicked the image on page, errors came out:
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)

It seems the onClick triggered java code can't find the method : delCondition1(int),  Why?  How can I set the method to call?

A:

You should not use zscript in production, this is suitable for prototyping only. See the statement from the ZK team.
If your image is defined in your ZUL file, simply use @Listen("onClick = #yourImageId") annotation on your method.
If your image is generated dynamically, use an EventListener to add the onClick event to your image :
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){
        ...
    }
}

See the documentation.

