Gerolf Seitz wrote:
> 
> On Dec 17, 2007 10:33 PM, Artur W. <[EMAIL PROTECTED]> wrote:
> 
>>
>> The component doesn't refresh. Only for the last time. How to make it
>> work?
>>
> 
> that's because the response is sent *AFTER* loop is over, not when
> target.addComponent(..) is called.
> what you need is a AjaxSelfUpdatingTimerBehavior, override
> onPostProcessTarget and do counter = counter +1; in there.
> 

Thanks for reply Guys! My business case is much more complicated. This was
just simple example.

I did like you said. It was interested that I had to start new thread to
process the loop.
Without it the label didn't refresh the counter value.

Here is my code, maybe it would be helpful for someone else:

                this.counter = 100

                final Label counterLabel = new Label("counter", new 
PropertyModel(this,
"counter"));
                counterLabel.add(new 
AjaxSelfUpdatingTimerBehavior(Duration.seconds(3)) {
                        @Override
                        protected void onPostProcessTarget(AjaxRequestTarget 
target) {
                                if (counter == 0) {
                                        
                                        //close the window after countdown :)
                                        window.close(target);
                                }
                        }
                });
                counterLabel.setOutputMarkupId(true);
                add(counterLabel);

                Form form = new Form("form");
                add(form);

                form.add(new IndicatingAjaxButton("confirmButton", form) {
                        @Override
                        protected void onSubmit(final AjaxRequestTarget target, 
Form form) {

                                setEnabled(false);
                                setOutputMarkupId(true);
                                target.addComponent(this);

                                new Thread() {

                                        public void run() {
                                                for (int i = 0; i &lt; 100; i++ 
) {
                                                        synchronized (this) {
                                                                
                                                                //do business 
here ;)
                                                                try { 
wait(300); } catch (InterruptedException e) {
e.printStackTrace(); }

                                                                counter--;
                                                        }
                                                }
                                        }
                                }.start();

                        }
                });


Btw, is is possible to add Behavior to the component in the
AjaxRequestTarget?
For exampel I want to add AjaxSelfUpdatingTimerBehavior but when the user
click on the button.


Thanks,
Artur
-- 
View this message in context: 
http://www.nabble.com/How-to-refresh-component-many-times-in-one-ajax-request-tp14374053p14387672.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to