-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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)));
Ok... after long elacubrations I solved in this way.
I hope will be useful
/Luca
timer.addEventListener("onReadTel", new EventListener()
{
@Override
public void onEvent(Event event) throws Exception
{
System.out.println("WWW");
}
});
timer.addEventListener("onTimer", new EventListener()
{
@Override
public void onEvent(Event event) throws Exception
{
lblOrario.setValue(dateFormat.format(java.util.Calendar.getInstance(locale).getTime()));
executor.execute(new RicontattoCellulareRun(desktop, gNazione, timer));
}
});
executor=RicontattoCellulare.getExecutor();
RicontattoCellulareRun
public class RicontattoCellulareRun implements Runnable
{
private final Desktop desktop;
private final Nazioni nazione;
private final Timer timer;
public RicontattoCellulareRun(Desktop desktop, Nazioni nazione, Timer timer)
{
this.desktop = desktop;
this.nazione = nazione;
this.timer = timer;
if(!desktop.isServerPushEnabled())
desktop.enableServerPush(true);
}
@Override
public void run()
{
try
{
Executions.activate(desktop);
TelefonateSuCellulareDAO tdao = (TelefonateSuCellulareDAO) SpringUtil.getBean("TelefonateSuCellulareDAO");
List<TelefonateSuCellulare> lstTel = tdao.findAll(nazione);
final Event event = new Event("onReadTel", timer, lstTel);
Executions.schedule(desktop, new EventListener<Event>() {
@Override
public void onEvent(Event evt) throws Exception
{
Events.sendEvent(evt);
}
}, event);
Executions.deactivate(desktop);
} catch (Exception e)
{
System.err.println("RicontattoCellulareRun: " + e.getMessage());
}
}
}
Thanks chillworld, any suggestion to resolve my problem? The purpose of performing this task every 5 minutes...
Asked: 2017-04-19 13:43:32 +0800
Seen: 36 times
Last updated: Apr 27 '17
Posting composer event [closed]
wrong valueException come in front of modal popup [closed]
Use parameters in a conditional @command
Problems with multiple press and onCtrlKey
MVVM @save on the fly [closed]
Unable to activate destroyed desktop
org.zkoss.zk.ui.UiException: java.lang.ClassNotFoundException
How to put a image or Letter over image on a specific XY Coordinate
last line,
chillworld ( 2017-04-20 06:41:56 +0800 )editnew RicontattoCellulareRun(desktop,(EventListener) timer, gNazione)
=> a timer isn't an eventListener.so your casting here is not correct.