# Progressmeter change while a process is running

Neus
1415 14

Hi,
I have a long process that goes over a list. To show the user how many items these process have checked I use a progress meter.
Now, it shows it to the user when all items have been scanned.
I want to change the progressmeter item by item. So, one item is scanned -> progressmeter move forward. Other item is scanned -> progressmeter move forward...

How can I do this?

Thank you!

delete retag edit

## 7 Replies

vincentjian
2245 6

Hi Neus,

You can modify the sample from zkdemo.
Here is the demo I modified: http://zkfiddle.org/sample/2ue3vcb/6-progressmeter-sample

Neus
1415 14

But in the example you provide, the progressmeter increase every 1 second, on the timer tick, isn't it?In my case, I run a server process for every item I need to scan. Maybe when it is runned for 1 item, the process takes 1 second. For another item maybe it takes more. I can't establish 1 second for every item. What I need is to increase the progressmeter when the process has complete.
I tried this:

for(int i=0;i<items;i++){
//Server process for the item
}
int current = ++percent * 100 / all;
progresoAcciones.setValue(current);
}



But progressmeter is still painted at the end of all

vincentjian
2245 6

Hi Neus,

I have modified the code, take a look on the zk fiddle. Not sure if it is the best implementation.

Neus
1415 14

Hi,
It's been a long since I started this thread but I'm with this problem yet.
I studied your example and I realize taht it is increasing using the tick of the timer, too. If I set the timer delay to 5000 the progressmeter is increased every 5 seconds so it is not taking into account when the server process ends.
I saw this post http://www.zkoss.org/forum/listComment/18987-Update-Progressmeter-form-java-controller?lang=en and I tried to get something straight about it but I'm not able to do that yet.
Any other idea to help me?
Thank you

vincentjian
2245 6

Hi Neus,

I tried to update progress meter by server push and it works. Here is the sample code:

<!-- ZUL page -->
<zk>
<window apply="test.ProgressComposer">
<progressmeter id="pm" value="0" />
<button id="btn" label="start" />
</window>
</zk>


public class ProgressComposer extends SelectorComposer<Window> {

private static final long serialVersionUID = -8327879927085566401L;

@Wire
private Progressmeter pm;
@WireVariable
private Desktop desktop;

private int all = 10;

public void run() {
if(!desktop.isServerPushEnabled())
return;

try {
for (int i = 1; i <= all; i++) {
long ms = (long) (Math.random() * 2000); //simulate long operation

Executions.activate(desktop);
progress(i);
Executions.deactivate(desktop);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
@Listen("onClick = #btn")
public void startProgress(Event event) {
desktop.enableServerPush(true);
}

private void progress(int current) {
pm.setValue(current * 100 /all);
if (current == all)
desktop.enableServerPush(false);
}
}


vincentjian
2245 6

And here is another solution if you would like to use EventQueue instead of ServePush:

public class ProgressComposer extends SelectorComposer<Window> {

private static final long serialVersionUID = -8327879927085566401L;

@Wire
private Progressmeter pm;
@WireVariable
private Desktop desktop;

private int all = 10;
private final EventQueue<Event> que = EventQueues.lookup("progress", EventQueues.SESSION, true);
public void run() {
try {
for (int i = 1; i <= all; i++) {
long ms = (long) (Math.random() * 2000); //simulate long operation

que.publish(new Event("next", null, new Integer(i)));
}
} catch (InterruptedException e) {
e.printStackTrace();
}

}
};
@Listen("onClick = #btn")
public void startProgress(Event event) {
}

@Subscribe(value = "progress", scope = EventQueues.SESSION)
public void progress(Event event) {
Integer current = (Integer) event.getData();
pm.setValue(current * 100 /all);
}
}


Senthilchettyin
2611 3 8
http://emrpms.blogspot.in...

Hi vincentjian

Can you give me the same in MVVM ?

[hide preview]