简体   繁体   中英

How to Add Java Method Timer for Redirect in ZK

Hello fellow developer,i've getting problem to set the Timer method on ZK,default the method in my.zul page is:

<timer id="timer" delay="1000" repeats="false"
onTimer="response.sendRedirect('./Login.zul')" />

but the code is error(i think beacuse ('./Login.zul'),if i try (\"./Login.zul\"),still show error),i try to build in my controller page like this:

     private Timer timer=new Timer( 1000 );

    public OTPController() {

        timer.setRepeats( true );
        timer.setAttribute( "onTimer","response.sendRedirect(\"./Login.zul\")", Timer.COMPONENT_SCOPE );

        timer.start();
}

but nothing happen..:(

anybody can help me?

maybe i have to create java script method or something like that? iam still trying to find the answer,ive read the ZK Docs but nothing can help..

Thanks for your attention and sorry for my bad english:D

You can try the following example,

<timer id="timer" delay="1000" repeats="false"
    onTimer='Executions.sendRedirect("./Login.zul")' />

onTimer

is an event not an attribute[1]. You should use addEventListener() [2] on your Timer component to add a method that does the actual sendRedirect. For eg. in your OTPController you can do

<!-- language: lang-js -->
timer.addEventListener(Events.ON_TIMER, new EventListener() {  
        public void onEvent(Event evt) {  
           Executions.sendRedirect("./Login.zul"); //refer [3]  
    }  
});

[1] http://books.zkoss.org/wiki/ZK_Component_Reference/Essential_Components/Timer#Supported_Events [2] http://books.zkoss.org/wiki/ZK_Developer 's_Reference/Event_Handling/Event_Listening#Event_Listener [3] http://books.zkoss.org/wiki/ZK_Developer 's_Reference/UI_Patterns/Forward_and_Redirect#Redirect_to_Another_URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM