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
精彩评论