Try to add logging, to see if the command is triggered. (I think that your second time hit an exception so logging in the catch would also be good)
chillworld ( 2015-03-18 07:16:58 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I have a very long data processing (Geocoding) and I'd like to display the customer's name inside the loop. I tried some solution but without success. Someone had a bright idea?
for (itCli = lstCli.iterator(); itCli.hasNext(); )
{
utCli = (Clienti)itCli.next();
countLetti++;
...display customer name here....
}
I don't think I'm making myself clear, Chill.
I would like display some data at screen during the process...like "System.out.println" but on screen. I did not find any solution. I tried with onTimer; Thread... I can't get this thing to work. The list was displayed at the end of loop...
<tabpanels width="480px">
<tabpanel>
<vlayout id="list" style="background: #FEFFCD; overflow:scroll; overflow-x:hidden"
action="show: slideDown;hide: slideUp" height="150px" />
</tabpanel>
</tabpanels>
.java (
for (itCli = lstCli.iterator(); itCli.hasNext(); )
{
utCli = (Clienti)itCli.next();
countLetti++;
list.appendChild(new Label("Name:"+...);
}
Thanks Chill, I tried with this code (before read your comment). The first time works fine, but if I press one more the command the program do not execute anything... Luca
<window id="win" title="Aggiornamenti vari" border="normal" apply="org.zkoss.bind.BindComposer" width="900px" closable="true"
viewModel="@id('vm') @init('rvl.gm.ui.Uti_aggiornamenti')">
<tabbox id="tbox" >
<tabs>
<tab id="elenco" label="Aggiornamento geolocalizzazione" />
</tabs>
<tabpanels>
<tabpanel>
<label value="Inserire l'iniziale del cognome da aggiornare" />
<textbox id="ragsoc" />
<separator></separator>
<progressmeter id="pm" value="0" width="100%" visible="false"/>
<vlayout id="list" style="background: #FEFFCD; overflow:scroll; overflow-x:hidden"
action="show: slideDown;hide: slideUp" height="350px" />
<button id="btnConferma" label="Conferma" onClick="@command('cmdGeolocalizzazione')" width="80px" />
</tabpanel>
</tabpanels>
</tabbox>
</window>
...and the java code....
private List<Clienti>lstCli;
private Clienti utCli = new Clienti();
private Iterator<Clienti> itCli;
private int countLetti=0, countAgg=0;
private ClientiDAO cli;
private Thread thread;
@Wire
private Window win;
@Wire
private Vlayout list;
@Wire
private Button btnConferma;
@Wire
private Textbox ragsoc;
@Wire
private Progressmeter pm;
@Command
public void cmdGeolocalizzazione(@SelectorParam("#list") final Vlayout vl)
{
pm.setVisible(true);
pm.setValue(0);
btnConferma.setDisabled(true);
utCli.setRagione_sociale(ragsoc.getValue());
utCli.setDes_comune("");
utCli.setDes_provincia("");
lstCli = cli.findFilter(utCli);
countLetti=0;
countAgg=0;
Runnable r = new Runnable()
{
@Override
public void run()
{
Desktop td = vl.getDesktop();
try
{
try
{
LatLng latlng=new LatLng();
for (itCli = lstCli.iterator(); itCli.hasNext(); )
{
countLetti++;
utCli = (Clienti)itCli.next();
Executions.activate(td);
Label l;
if(utCli.getLatitudine().abs().compareTo(BigDecimal.ZERO )==0 &&
utCli.getLongitudine().abs().compareTo(BigDecimal.ZERO)==0)
{
try
{
latlng = uv.retCoordinate3(utCli);
if(latlng!=null)
{
utCli.setLatitudine(latlng.getLat());
utCli.setLongitudine(latlng.getLng());
cli.update(utCli);
countAgg++;
l = new Label("Clienti presenti:"+lstCli.size()
+" Aggiornati:"+countAgg
+" RagioneSociale:"
+" "+utCli.getRagione_sociale().substring(0, utCli.getRagione_sociale().length()>30 ? 30 : utCli.getRagione_sociale().length())+" ("+utCli.getProgressivo()+")");
l.setAction("show: slideDown");
if (list.getChildren().size() != 0)
{
list.insertBefore(l, (Component) list.getChildren().get(0));
} else {
l.setParent(list);
}
}
} catch (Exception e)
{
l = new Label("Problema nel cliente:\n"+utCli.getProgressivo()+
" "+utCli.getRagione_sociale()+","+utCli.getIndirizzo()+"\n"+
utCli.getCap()+","+utCli.getDes_comune()+"\n"+
"Errore: "+e.getMessage());
l.setAction("show: slideDown");
if (list.getChildren().size() != 0)
{
list.insertBefore(l, (Component) list.getChildren().get(0));
} else {
l.setParent(list);
}
if(Thread.currentThread().isAlive())
{
Thread.currentThread().interrupt();
}
break;
}
}
pm.setValue(countLetti * 100 / lstCli.size());
if(countLetti>=lstCli.size())
{
pm.setVisible(false);
btnConferma.setDisabled(false);
l = new Label("Elaborazione terminata per RagSoc="+ragsoc.getValue()+" Clienti letti:"+countLetti+" aggiornati:"+countAgg);
l.setAction("show: slideDown");
if (list.getChildren().size() != 0)
{
list.insertBefore(l, (Component) list.getChildren().get(0));
} else {
l.setParent(list);
}
if(Thread.currentThread().isAlive())
{
Thread.currentThread().interrupt();
}
}
BindUtils.postNotifyChange(null, null, this, "list");
BindUtils.postNotifyChange(null, null, this, "pm");
Executions.deactivate(td);
}
}
finally
{
}
}
catch (DesktopUnavailableException e)
{
Thread.currentThread().interrupt();
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();
}
}
};
thread = new Thread(r);
thread.start();
}
Try to add logging, to see if the command is triggered. (I think that your second time hit an exception so logging in the catch would also be good)
chillworld ( 2015-03-18 07:16:58 +0800 )editHi lramellavotta,
have you seen this 'small talk' from Robert ? http://books.zkoss.org/wiki/SmallTalks/2015/January/SimplifyLongOperationHandlings
An other approach is to do such things with the help of websockets.
"Long running process with immediatelly information in the UI"
Visualize a long running process!
At the end of the next video i setup the sample message scheduler up to 50ms. Have a look. The 'websocket' runs indepentend of ZK.
second video best Stephan
Hi TerryTornado, There's a example available for websocket? I tried many solution without success...
@lramellavotta,
you can take the admin realtime dashboard module. There's the simple notifier in it. Does run without ZKBoost also. and skype me: TerryTornado
websocket realtime admin dashboard
best Stephan
Thanks terrytornado, I'd like to thank you for your help. I can't use skype: You will understand nothing with my type of English. :)
lramellavotta ( 2015-03-27 10:13:50 +0800 )editThis code works much better.
lstCli is a List of Clienti class read from a mysql db.
I hope this example wont it someone.
private ExecutorService executorService;
private Callable<Boolean> callable = new Callable<Boolean>()
{
@Override
public Boolean call() throws Exception
{
countLetti=0;
for (itCli = lstCli.iterator(); itCli.hasNext(); )
{
utCli = (Clienti)itCli.next();
countLetti++;
if(utCli.getAutorizzazione_contatto() && utCli.getLatitudine().compareTo(BigDecimal.ZERO)==0 &&
utCli.getLongitudine().compareTo(BigDecimal.ZERO)==0)
{
System.out.println("Sono nel ciclo "+countLetti+" su un totale di "+lstCli.size()+" "
+(countLetti * 100 / lstCli.size())+"% Cliente: "
+utCli.getRagione_sociale()+" ");
calcolaCoordinate();
aggiornaCliente();
}
}
return true;
}
};
@Command
public void cmdGeolocalizzazione()
{
Object ok=null;
Future<Boolean> future;
executorService = Executors.newSingleThreadExecutor();
if (!desktop.isServerPushEnabled()) desktop.enableServerPush(true);
try
{
System.out.println("Asynchronous call started at:"+ISODateTimeFormat.hourMinuteSecond().print(LocalTime.now()));
caricaClienti();
future = executorService.submit(callable);
ok=future.get();
}catch (Exception e)
{
System.out.println("Errore:"+e.getMessage());
}finally
{
executorService.shutdownNow();
if (desktop.isServerPushEnabled()) desktop.enableServerPush(false);
System.out.println("Asynchronous call finish at:"+ISODateTimeFormat.hourMinuteSecond().print(LocalTime.now()));
}
if(ok==null || ((Boolean) ok)==false)
{
System.out.println("Elaborazione terminata con errore..");
}
}
private void caricaClienti() throws DataAccessException
{
utCli = new Clienti();
utCli.setRagione_sociale(txtRagSoc.getValue());
utCli.setDes_comune("");
utCli.setDes_provincia("");
lstCli = cli.findFilter(utCli,360);
}
Oh, maybe I spoke too soon...
When I run this function I receive an error: Before calling Executions.activate(), the server push must be enabled
but I enable serverPush at cmdGeolocalizzazione()...
Any Idea?
private void aggiornaCliente() throws DesktopUnavailableException, InterruptedException, Exception
{
Executions.activate(desktop);
ClientiDAO cliUpd = (ClientiDAO)SpringUtil.getBean("ClientiDAO");
cliUpd.update(utCli);
Executions.deactivate(desktop);
}
Here's a hint; Executions.getCurrent() return null in function call()...
I'm a little confused.
I made many attempts but do not work... I just can't come up with anything....
Asked: 2015-03-16 17:15:43 +0800
Seen: 82 times
Last updated: Apr 29 '15
zk.wpd JS error, with window inside window
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