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