Hi Toscano, 

I solved this by making an AJAX call in order to change the pic. I don't
know if it's possible for your app to use AJAX (and thus depend on enabled
javascript on client side) - but here's my code

final TextField t;
                final NonCachingImage img;
                add(img = new NonCachingImage("captchaImage",
_captchaService.getCaptchaImageForId(_challengeId)));
                add(t = new TextField("captchaField", new Model()));            
                img.setOutputMarkupId(true);
                
                add(new AjaxFallbackLink("changeCaptcha") {

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                                if (target != null) {
                                        NonCachingImage newImg = new 
NonCachingImage("captchaImage",
_captchaService.changeCaptchaImageForId(_challengeId));
                                        
                                        CaptchaPanel.this.replace(newImg);
                                        target.addComponent(newImg, 
img.getMarkupId());
                                }
                                
                        }
                        
                });


The "CaptchaPanel" is just the Panel holding the link and the image - the
service just returns a CaptchaImageSource, nothing special about it.
But be sure to set outputmarkupId to true AND be sure to use a non-caching
image, otherwise a cached image on the client side could be used instead of
the new image. 
i hope i could help you

michael

PS: looking at my code, i realised that it may be better to use AjaxLink
instead of AjaxFallbackLink as it would result in a NPE if no JS is
available :-)

Toscano wrote:
> 
> Hello,
> 
> I'm having problems with a Captcha image reloading method, and I'm sure it
> must be very easy to solve, but I can't!!
> I have a form with about 10 fields, and at the end one Captcha image using
> CaptchaImageResource and Image controls. Sometimes it is difficult to
> read, so I put one link with the following OnClick code:
> 
>    public void onClick()
>       {
>              imagePass=randomString(6,8);
>              captchaImageResource = new CaptchaImageResource(imagePass);
>              captchaImage.setImageResource(captchaImageResource);
>       }
> 
> I mean, I create a new captcha image correctly, but all the content of the
> fields are removed! This means that the user has to input them again. I
> think it is just a matter of the Link... if I just leave the OnClick code
> blank, it reloads the page without maintaining the values.
> 
>  I have a Form and a CompoundPropertyModel which works fine:
> 
>      // Form, pojo, and compound property model
>       InitiationForm initiationForm;
>       NewUser newUser;
>       CompoundPropertyModel initiationFormModel;
> 
>     //Create CompoundPropertyModel
>     initiationFormModel = new CompoundPropertyModel(newUser);
> 
>    // Form
>    initiationForm = new InitiationForm ("initiationForm",
> initiationFormModel);
> 
> 
> How can I refresh the image without losing the already input values?
> 
> Thank you very very much for your time!
> Oskar
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Reload-Captcha-Image-tf4674760.html#a13358415
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