You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by triswork <tr...@gmail.com> on 2009/03/24 16:12:10 UTC

Form validation without a form component

One of my forms is used to dynamically construct a linked list using Ajax.

I would like to apply some form of validation to this form that will show an
error unless the size of the list is greater than 0. 

The trouble is that there is no form component that I can add my validator
to. Is there a sensible way to do this?
-- 
View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22682572.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 validation without a form component

Posted by scotthendo <sc...@gmail.com>.
Hi Antoine,

I am doing something similar and was wondering if you could help. I am
trying to validate a large form by overriding the onValidate method but when
I do, all the form values are null.

Some code snippets:

public final class DatasetForm extends Form
    {
        private final DatasetTO dataset = new DatasetTO();
        
        public DatasetForm(final String componentName)
        {
            super(componentName);
            
            add(new TextField("orgName", new PropertyModel(dataset,
"orgName")));

       }

        public final void onSubmit()
        {
              System.out.println(dataset.getOrgName()); // this works fine
and displays the value
        }


         public final void onValidate()
        {
           System.out.println(dataset.getOrgName()); // here it is set to
null
         } 
}

So how can i access the form values from onValidate()

Thanks in advance, scott.


Antoine van Wel wrote:
> 
> for the archive-searchers :)
> 
> simply override onValidate in the Form class, check your listsize
> there & call error() when applicable
> 
> 
> Antoine
> 
> On Fri, Apr 3, 2009 at 12:25 PM, triswork <tr...@gmail.com> wrote:
>>
>> Thanks for the suggestion Martijn.
>> I tried return new FormComponent[0]; and got exactly the same error.
>>
>> I think my use-case is quite fringe, so I have resigned myself to using
>> the
>> hidden field that you previously suggested.
>>
>>  - Tristan
>>
>>
>> Martijn Dashorst wrote:
>>>
>>> You might try to return an empty array..
>>>
>>> Martijn
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22866535.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
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Form-validation-without-a-form-component-tp22682572p27845370.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 validation without a form component

Posted by Antoine van Wel <an...@gmail.com>.
for the archive-searchers :)

simply override onValidate in the Form class, check your listsize
there & call error() when applicable


Antoine

On Fri, Apr 3, 2009 at 12:25 PM, triswork <tr...@gmail.com> wrote:
>
> Thanks for the suggestion Martijn.
> I tried return new FormComponent[0]; and got exactly the same error.
>
> I think my use-case is quite fringe, so I have resigned myself to using the
> hidden field that you previously suggested.
>
>  - Tristan
>
>
> Martijn Dashorst wrote:
>>
>> You might try to return an empty array..
>>
>> Martijn
>>
>
> --
> View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22866535.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 validation without a form component

Posted by triswork <tr...@gmail.com>.
Thanks for the suggestion Martijn. 
I tried return new FormComponent[0]; and got exactly the same error.

I think my use-case is quite fringe, so I have resigned myself to using the
hidden field that you previously suggested.

 - Tristan


Martijn Dashorst wrote:
> 
> You might try to return an empty array..
> 
> Martijn
> 

-- 
View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22866535.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 validation without a form component

Posted by Martijn Dashorst <ma...@gmail.com>.
You might try to return an empty array..

Martijn

On Thu, Mar 26, 2009 at 10:37 AM, triswork <tr...@gmail.com> wrote:
>
> Thanks igor,
>
> I had a go at implementing the form level validator, but it still requires a
> FormComponent to attach its error message to.
>
> For example:
> form.add(new IFormValidator() {
>  @Override
>  public void validate(Form f) {
>    if (myList.size() == 0)  {
>      f.error(new ValidationError().addMessageKey("error.myErrorMessage"));
>    }
>  }
>
>  @Override
>  public FormComponent[] getDependentFormComponents() {
>    return null;
>  }
> });
>
> If I don't return a FormComponent in getDependentFormComponents(), I get the
> following message in my Feedback Panel:
> [ValidationError message=[null], keys=[error.myErrorMessage],
> variables=[null]]
>
> Is there a way around this that you are aware of?
>
> T
>
>
> igor.vaynberg wrote:
>>
>> see IFormValidator
>>
>> -igor
>>
>
> --
> View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22717797.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
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

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


Re: Form validation without a form component

Posted by triswork <tr...@gmail.com>.
Thanks igor,

I had a go at implementing the form level validator, but it still requires a
FormComponent to attach its error message to.

For example:
form.add(new IFormValidator() {
  @Override
  public void validate(Form f) {
    if (myList.size() == 0)  {
      f.error(new ValidationError().addMessageKey("error.myErrorMessage"));
    }
  }

  @Override
  public FormComponent[] getDependentFormComponents() {
    return null;
  }
});

If I don't return a FormComponent in getDependentFormComponents(), I get the
following message in my Feedback Panel:
[ValidationError message=[null], keys=[error.myErrorMessage],
variables=[null]]

Is there a way around this that you are aware of?

T


igor.vaynberg wrote:
> 
> see IFormValidator
> 
> -igor
> 

-- 
View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22717797.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 validation without a form component

Posted by Igor Vaynberg <ig...@gmail.com>.
see IFormValidator

-igor

On Wed, Mar 25, 2009 at 9:39 AM, triswork <tr...@gmail.com> wrote:
>
> Nope. As far as I can tell, you can only add Validators to subclasses of
> FormComponent.
>
>
> James Carman-3 wrote:
>>
>> You could add a validator to the form itself, right?
>>
>
> --
> View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22705787.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 validation without a form component

Posted by triswork <tr...@gmail.com>.
Nope. As far as I can tell, you can only add Validators to subclasses of
FormComponent.


James Carman-3 wrote:
> 
> You could add a validator to the form itself, right?
> 

-- 
View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22705787.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 validation without a form component

Posted by James Carman <jc...@carmanconsulting.com>.
You could add a validator to the form itself, right?

On Tue, Mar 24, 2009 at 12:02 PM, triswork <tr...@gmail.com> wrote:
>
> Hi Martijn,
> The hidden worked fine.
> I thought there might be a more elegant way though :)
>
> Tristan
>
>
> Martijn Dashorst wrote:
>>
>> You could try adding a hidden field and register a validator to that
>> field...
>>
>> I have no idea if that would work though....
>>
>> Martijn
>>
>
> --
> View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22683664.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 validation without a form component

Posted by triswork <tr...@gmail.com>.
Hi Martijn,
The hidden worked fine. 
I thought there might be a more elegant way though :)

Tristan


Martijn Dashorst wrote:
> 
> You could try adding a hidden field and register a validator to that
> field...
> 
> I have no idea if that would work though....
> 
> Martijn
> 

-- 
View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22683664.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 validation without a form component

Posted by Martijn Dashorst <ma...@gmail.com>.
You could try adding a hidden field and register a validator to that field...

I have no idea if that would work though....

Martijn

On Tue, Mar 24, 2009 at 4:12 PM, triswork <tr...@gmail.com> wrote:
>
> One of my forms is used to dynamically construct a linked list using Ajax.
>
> I would like to apply some form of validation to this form that will show an
> error unless the size of the list is greater than 0.
>
> The trouble is that there is no form component that I can add my validator
> to. Is there a sensible way to do this?
> --
> View this message in context: http://www.nabble.com/Form-validation-without-a-form-component-tp22682572p22682572.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
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.

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