0

How to display data during iterator loop?

asked 2015-03-16 17:15:43 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

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....
    }
delete flag offensive retag edit

18 Answers

Sort by ยป oldest newest most voted
0
link publish delete flag offensive edit
0

answered 2015-03-17 15:47:45 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

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:"+...);
}
link publish delete flag offensive edit
0

answered 2015-03-17 20:20:10 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

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();
}
link publish delete flag offensive edit

Comments

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
0

answered 2015-03-18 09:02:41 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2015-03-18 09:14:54 +0800

Hi 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

link publish delete flag offensive edit
0

answered 2015-03-24 10:40:19 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

Hi TerryTornado, There's a example available for websocket? I tried many solution without success...

link publish delete flag offensive edit
0

answered 2015-03-26 19:25:12 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2015-03-26 19:26:16 +0800

@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

link publish delete flag offensive edit

Comments

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 )edit
0

answered 2015-03-27 12:18:52 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

This 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);
}
link publish delete flag offensive edit
0

answered 2015-03-29 18:02:46 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

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);
}
link publish delete flag offensive edit
0

answered 2015-03-29 21:12:42 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

Here's a hint; Executions.getCurrent() return null in function call()...

I'm a little confused.

link publish delete flag offensive edit
0

answered 2015-04-13 15:24:00 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

I made many attempts but do not work... I just can't come up with anything....

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2015-03-16 17:15:43 +0800

Seen: 81 times

Last updated: Apr 29 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More