You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Nicola Tucci <ny...@gmail.com> on 2009/08/03 15:06:11 UTC

Form skips validation for disabled/not visible components

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

Re: Form skips validation for disabled/not visible components

Posted by nytrus <ny...@gmail.com>.

James Carman-3 wrote:
> 
> And, if you want to display the currently-selected "thing", then try
> using a label (with a little style to it perhaps).
> 
> On Mon, Aug 3, 2009 at 11:23 AM, Igor Vaynberg<ig...@gmail.com>
> wrote:
>> use HiddenField instead of a TextField, that way there is no need to
>> disable it.
>>
>> then the textfield/lookup button can be client-side things that
>> populate the hidden field.
>>
>> -igor
> 

Yes HiddenField is nice stuff! I will use IFormValidator as I've to
re-utilize it in several places. Thank you all!
-- 
View this message in context: http://www.nabble.com/Form-skips-validation-for-disabled-not-visible-components-tp24790510p24809865.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Form skips validation for disabled/not visible components

Posted by James Carman <jc...@carmanconsulting.com>.
And, if you want to display the currently-selected "thing", then try
using a label (with a little style to it perhaps).

On Mon, Aug 3, 2009 at 11:23 AM, Igor Vaynberg<ig...@gmail.com> wrote:
> use HiddenField instead of a TextField, that way there is no need to disable it.
>
> then the textfield/lookup button can be client-side things that
> populate the hidden field.
>
> -igor
>
> On Mon, Aug 3, 2009 at 7:51 AM, nytrus<ny...@gmail.com> wrote:
>>
>>
>> egolan74 wrote:
>>>
>>> 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.
>>>
>>
>> 1. Good observation, but my goal is checking for required fields.
>> 2. That's an idea: I can write my class imlpementing IFormValidator and then
>> add this to the container form. For checking required fields somethign like
>> this could work:
>>
>> public class RequiredFieldsValidator extends AbstractFormValidator {
>>    private List<FormComponents> components;
>>
>>    public RequiredFieldsValidator(List<FormComponents> components) {
>>        this.components = components;
>>    }
>>
>>    public void validate(Form<?> form)
>>    {
>>         for(FormComponent c: components) {
>>              validateRequired();
>>         }
>>    }
>> }
>>
>> --
>> View this message in context: http://www.nabble.com/Form-skips-validation-for-disabled-not-visible-components-tp24790510p24792189.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Form skips validation for disabled/not visible components

Posted by Eyal Golan <eg...@gmail.com>.
HiddenField is a good thing to know about :)

Eyal Golan
egolan74@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 5:23 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> use HiddenField instead of a TextField, that way there is no need to
> disable it.
>
> then the textfield/lookup button can be client-side things that
> populate the hidden field.
>
> -igor
>
> On Mon, Aug 3, 2009 at 7:51 AM, nytrus<ny...@gmail.com> wrote:
> >
> >
> > egolan74 wrote:
> >>
> >> 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.
> >>
> >
> > 1. Good observation, but my goal is checking for required fields.
> > 2. That's an idea: I can write my class imlpementing IFormValidator and
> then
> > add this to the container form. For checking required fields somethign
> like
> > this could work:
> >
> > public class RequiredFieldsValidator extends AbstractFormValidator {
> >    private List<FormComponents> components;
> >
> >    public RequiredFieldsValidator(List<FormComponents> components) {
> >        this.components = components;
> >    }
> >
> >    public void validate(Form<?> form)
> >    {
> >         for(FormComponent c: components) {
> >              validateRequired();
> >         }
> >    }
> > }
> >
> > --
> > View this message in context:
> http://www.nabble.com/Form-skips-validation-for-disabled-not-visible-components-tp24790510p24792189.html
> > Sent from the Wicket - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Form skips validation for disabled/not visible components

Posted by Igor Vaynberg <ig...@gmail.com>.
use HiddenField instead of a TextField, that way there is no need to disable it.

then the textfield/lookup button can be client-side things that
populate the hidden field.

-igor

On Mon, Aug 3, 2009 at 7:51 AM, nytrus<ny...@gmail.com> wrote:
>
>
> egolan74 wrote:
>>
>> 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.
>>
>
> 1. Good observation, but my goal is checking for required fields.
> 2. That's an idea: I can write my class imlpementing IFormValidator and then
> add this to the container form. For checking required fields somethign like
> this could work:
>
> public class RequiredFieldsValidator extends AbstractFormValidator {
>    private List<FormComponents> components;
>
>    public RequiredFieldsValidator(List<FormComponents> components) {
>        this.components = components;
>    }
>
>    public void validate(Form<?> form)
>    {
>         for(FormComponent c: components) {
>              validateRequired();
>         }
>    }
> }
>
> --
> View this message in context: http://www.nabble.com/Form-skips-validation-for-disabled-not-visible-components-tp24790510p24792189.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Form skips validation for disabled/not visible components

Posted by nytrus <ny...@gmail.com>.

egolan74 wrote:
> 
> 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.
> 

1. Good observation, but my goal is checking for required fields.
2. That's an idea: I can write my class imlpementing IFormValidator and then
add this to the container form. For checking required fields somethign like
this could work:

public class RequiredFieldsValidator extends AbstractFormValidator {
    private List<FormComponents> components;

    public RequiredFieldsValidator(List<FormComponents> components) {
        this.components = components;
    }

    public void validate(Form<?> form)
    {
         for(FormComponent c: components) {
              validateRequired();
         }
    }
}

-- 
View this message in context: http://www.nabble.com/Form-skips-validation-for-disabled-not-visible-components-tp24790510p24792189.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Form skips validation for disabled/not visible components

Posted by Eyal Golan <eg...@gmail.com>.
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
egolan74@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 <ny...@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
>