1. If you in control of the input of these disabled fields, why allowing
illegal arguments in the first place?
2. If you can't control the entered values, try use FormValidator. With this
class, you can create your own Validate logic with the desired fields.

Eyal Golan
egola...@gmail.com

Visit: http://jvdrums.sourceforge.net/
LinkedIn: http://www.linkedin.com/in/egolan74

P  Save a tree. Please don't print this e-mail unless it's really necessary


On Mon, Aug 3, 2009 at 4:06 PM, Nicola Tucci <nytrus...@gmail.com> wrote:

> Hi all! I've a situation where I want the form to validate some hidden or
> disabled field.
>
> An example is a text field where the user is not allowed to write directly
> but only insert some items from some source, a lookup button.... (this is
> much more flexible than a drop down box!).
> I set this component disabled with .setEnabled(false). Now when the form is
> validated, the validation for my textfield is skipped (see Form class in
> wicket 1.4 rc4):
>
> public static abstract class ValidationVisitor implements
> FormComponent.IVisitor
>    {
>        public Object formComponent(IFormVisitorParticipant component)
>        {
>            if (component instanceof FormComponent)
>            {
>                FormComponent<?> formComponent =
> (FormComponent<?>)component;
>
>                Form<?> form = formComponent.getForm();
>                if (!form.isVisibleInHierarchy() ||
> !form.isEnabledInHierarchy())
>                {
>                    // do not validate formComponent or any of
> formComponent's children
>                    return
> Component.IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
>                }
>                /** HERE WE SKIP!!! */
>                if (formComponent.isVisibleInHierarchy() &&
> formComponent.isValid() &&
>                    formComponent.isEnabledInHierarchy())
>                {
>                    validate(formComponent);
>                }
>            }
>            if (component.processChildren())
>            {
>                return Component.IVisitor.CONTINUE_TRAVERSAL;
>            }
>            else
>            {
>                return
> Component.IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
>            }
>        }
>
> Now I can override this, as Form.validateComponents() if final. I could
> only
> override Form.onSubmit() and doing an ad-hoc validation (not very good).
>
> Some hint? Thanks folk
>

Reply via email to