Gerolf Seitz wrote:
> 
> ditch the form and let CaptchaPanel extend FormComponentPanel. for the
> captcha and do a check for the form in onBeforeRender (since it's not yet
> added to the hierarchy in the constructor).
> just use "getForm();" to check for the existence of an ancestor form. this
> method throws an exception if no form was found.
> 

I'd suggest that it extend Panel, not FormComponentPanel as there is no
composite data structure here. The best place to validate the input is
in a custom validator. Here is some sample code (there is also step-by-
step instruction on validation in my tutorials; see my signature):

public class CaptchaPanel extends Panel {
        private static class CaptchaValidator extends AbstractValidator {
                protected void onValidate(IValidatable validatable) {
                        String value = (String) validatable.getValue();
                        if (value matches the image) {
                                return;
                        }
                        error(validatable);
                }
        }
        public CaptchaPanel(String id) {
                super(id);
                RequiredTextField t = new RequiredTextField("captchaInput", new 
Model());
                t.add(new CaptchaValidator());
                add(t);
                add(new Image("captchaImage", ...));
        }
}


-----
--
Kent Tong
Wicket tutorials freely available at http://www.agileskills2.org/EWDW
-- 
View this message in context: 
http://www.nabble.com/Decouple-parts-of-a-form-tf4591493.html#a13112961
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