-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1 | initial version | |
This is my Achilles' heel... I'd like to read cyclically some data from db and warn the user on specified presence of event. I tried writing some solution...without success. Now the error is : "org.zkoss.zul.Timer cannot be cast to org.zkoss.zk.ui.event.EventListener"
Can someone help me? thanks, /Luca
zk.xml
<listener>
<description>Utilizzato leggere dal database </description>
<display-name>Ricontatto cellulare </display-name>
<listener-class>rvl.gm.utility.RicontattoCellulare</listener-class>
</listener>
RicontattoCellulare
public class RicontattoCellulare implements WebAppInit, WebAppCleanup
{
private static volatile ExecutorService executor;
public static ExecutorService getExecutor()
{
return executor;
}
@Override
public void cleanup(WebApp wapp) throws Exception
{
if (executor != null)
{
executor.shutdown();
System.out.println("ExecutorService gestione telefonate a cellulare ->shutdown");
}
}
@Override
public void init(WebApp wapp) throws Exception
{
executor = Executors.newSingleThreadExecutor();
System.out.println("ExecutorService gestione telefonate a cellulare ->startup");
}
}
RicontattoCellulareRun
public class RicontattoCellulareRun implements Runnable
{
private final Desktop desktop;
private final EventListener<Event> eventListener;
private final Nazioni gNazione;
@SuppressWarnings({ "rawtypes", "unchecked" })
public RicontattoCellulareRun(Desktop desktop, EventListener eventListener, Nazioni gNazione)
{
this.desktop = desktop;
this.eventListener = eventListener;
this.gNazione = gNazione;
}
@Override
public void run()
{
try
{
desktop.enableServerPush(true);
TelefonateSuCellulareDAO tdao = (TelefonateSuCellulareDAO) SpringUtil.getBean("TelefonateSuCellulareDAO");
List<TelefonateSuCellulare> lstTel = tdao.findAll(gNazione);
Executions.schedule(desktop, eventListener, new Event("onReadTel",null, lstTel));
desktop.enableServerPush(false);
} catch (Exception e)
{
System.err.println("RicontattoCellulareRun: " + e.getMessage());
}
}
}
Menu
@Wire("#timer")
Timer timer;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view)
{
...
timer.addEventListener("onReadTel", new EventListener()
{
@Override
public void onEvent(Event event) throws Exception
{
System.out.println("WWW");
}
});
RicontattoCellulare.getExecutor().execute((new RicontattoCellulareRun(desktop,(EventListener) timer, gNazione)));
2 | No.2 Revision |
This is my Achilles' heel... I'd like to read cyclically some data from db and warn the user on specified presence of event. I tried writing some solution...without success. Now the error is : "org.zkoss.zul.Timer cannot be cast to org.zkoss.zk.ui.event.EventListener"
Can someone help me? thanks, /Luca
zk.xml
<listener>
<description>Utilizzato leggere dal database </description>
<display-name>Ricontatto cellulare </display-name>
<listener-class>rvl.gm.utility.RicontattoCellulare</listener-class>
</listener>
RicontattoCellulare
public class RicontattoCellulare implements WebAppInit, WebAppCleanup
{
private static volatile ExecutorService executor;
public static ExecutorService getExecutor()
{
return executor;
}
@Override
public void cleanup(WebApp wapp) throws Exception
{
if (executor != null)
{
executor.shutdown();
System.out.println("ExecutorService gestione telefonate a cellulare ->shutdown");
}
}
@Override
public void init(WebApp wapp) throws Exception
{
executor = Executors.newSingleThreadExecutor();
System.out.println("ExecutorService gestione telefonate a cellulare ->startup");
}
}
RicontattoCellulareRun
public class RicontattoCellulareRun implements Runnable
{
private final Desktop desktop;
private final EventListener<Event> eventListener;
private final Nazioni gNazione;
@SuppressWarnings({ "rawtypes", "unchecked" })
public RicontattoCellulareRun(Desktop desktop, EventListener eventListener, Nazioni gNazione)
{
this.desktop = desktop;
this.eventListener = eventListener;
this.gNazione = gNazione;
}
@Override
public void run()
{
try
{
desktop.enableServerPush(true);
TelefonateSuCellulareDAO tdao = (TelefonateSuCellulareDAO) SpringUtil.getBean("TelefonateSuCellulareDAO");
List<TelefonateSuCellulare> lstTel = tdao.findAll(gNazione);
Executions.schedule(desktop, eventListener, new Event("onReadTel",null, lstTel));
desktop.enableServerPush(false);
} catch (Exception e)
{
System.err.println("RicontattoCellulareRun: " + e.getMessage());
}
}
}
Menu
@Wire("#timer")
Timer timer;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view)
{
...
timer.addEventListener("onReadTel", new EventListener()
{
@Override
public void onEvent(Event event) throws Exception
{
System.out.println("WWW");
}
});
RicontattoCellulare.getExecutor().execute((new RicontattoCellulareRun(desktop,(EventListener) timer, gNazione)));