You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Christian Smolka <ch...@etecture.de> on 2014/04/14 19:45:02 UTC

Validating multiple components as one

Hi to everybody!

My little problem is about validating multiple input fields as a single one.
So, I have three DoB fields (one for the day, one for the month and one
for the
year) that should be validated as a single date.

While using Wicket 1.5 we overwrote AjaxEventBehavior#getEventHandler() and
returned a custom made JavaScript that serialized the three fields like
this:


StringBuffer buffer = new StringBuffer("wicketAjaxPost('")
    .append(this.getCallbackUrl()).append("', ");
for (String id : this.getInputIds()) {
    buffer.append("wicketSerialize(Wicket.$('").append(id).append("')) + ");
}
buffer.setLength(buffer.length() - 3);
return buffer;


This worked pretty well. But I have to migrate the application to Wicket 6
and this doing does work anymore. As far as I understood the new Ajax-way,
it isn't possible anymore to provide a custom script like the one above. But
how can I restore the old behavior? Do I have to put the fields into a
form and
submit the whole form to validate it?

Thanks in advance!


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


Re: Validating multiple components as one

Posted by Christian Smolka <ch...@etecture.de>.
Hi Martin,

thanks for your reply, it definitely made my day! I had to tweak the
snippet a little, because Wicket.Form.serialize() returns an array of
objects that does not really work out for the AJAX request. So I changed
the value expression into Wicket.$(id).value and that worked perfectly.

Thanks a lot!
Christian

> Hi,
>
> The new way is to use the dynamic extra parameters.
> Each Ajax behavior and component has a method
> #updateAjaxAttributes(AjaxRequestAttributes attributes) :
>
> attributes.getDynamicExtraParameters().add("return [obj1, obj2, ...]").
>
> Where objN are JavaScript objects like: {"name":
> formComponent.getInputName(), "value":
> Wicket.Form.serialize(Wicket.$('"+formComponent.getMarkupId()+"')) }
>
> The above is a pseudo code but I hope you follow me.
>
>
> Martin Grigorov
> Wicket Training and Consulting
>
>
> On Mon, Apr 14, 2014 at 8:45 PM, Christian Smolka <
> christian.smolka@etecture.de> wrote:
>
>> Hi to everybody!
>>
>> My little problem is about validating multiple input fields as a single
>> one.
>> So, I have three DoB fields (one for the day, one for the month and one
>> for the
>> year) that should be validated as a single date.
>>
>> While using Wicket 1.5 we overwrote AjaxEventBehavior#getEventHandler() and
>> returned a custom made JavaScript that serialized the three fields like
>> this:
>>
>>
>> StringBuffer buffer = new StringBuffer("wicketAjaxPost('")
>>     .append(this.getCallbackUrl()).append("', ");
>> for (String id : this.getInputIds()) {
>>     buffer.append("wicketSerialize(Wicket.$('").append(id).append("')) +
>> ");
>> }
>> buffer.setLength(buffer.length() - 3);
>> return buffer;
>>
>>
>> This worked pretty well. But I have to migrate the application to Wicket 6
>> and this doing does work anymore. As far as I understood the new Ajax-way,
>> it isn't possible anymore to provide a custom script like the one above.
>> But
>> how can I restore the old behavior? Do I have to put the fields into a
>> form and
>> submit the whole form to validate it?
>>
>> Thanks in advance!
>>
>>
>> ---------------------------------------------------------------------
>> 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: Validating multiple components as one

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

The new way is to use the dynamic extra parameters.
Each Ajax behavior and component has a method
#updateAjaxAttributes(AjaxRequestAttributes attributes) :

attributes.getDynamicExtraParameters().add("return [obj1, obj2, ...]").

Where objN are JavaScript objects like: {"name":
formComponent.getInputName(), "value":
Wicket.Form.serialize(Wicket.$('"+formComponent.getMarkupId()+"')) }

The above is a pseudo code but I hope you follow me.


Martin Grigorov
Wicket Training and Consulting


On Mon, Apr 14, 2014 at 8:45 PM, Christian Smolka <
christian.smolka@etecture.de> wrote:

> Hi to everybody!
>
> My little problem is about validating multiple input fields as a single
> one.
> So, I have three DoB fields (one for the day, one for the month and one
> for the
> year) that should be validated as a single date.
>
> While using Wicket 1.5 we overwrote AjaxEventBehavior#getEventHandler() and
> returned a custom made JavaScript that serialized the three fields like
> this:
>
>
> StringBuffer buffer = new StringBuffer("wicketAjaxPost('")
>     .append(this.getCallbackUrl()).append("', ");
> for (String id : this.getInputIds()) {
>     buffer.append("wicketSerialize(Wicket.$('").append(id).append("')) +
> ");
> }
> buffer.setLength(buffer.length() - 3);
> return buffer;
>
>
> This worked pretty well. But I have to migrate the application to Wicket 6
> and this doing does work anymore. As far as I understood the new Ajax-way,
> it isn't possible anymore to provide a custom script like the one above.
> But
> how can I restore the old behavior? Do I have to put the fields into a
> form and
> submit the whole form to validate it?
>
> Thanks in advance!
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Validating multiple components as one

Posted by Christian Smolka <ch...@etecture.de>.
Hi Sven,

unfortunately it would be a too great effort to change every usage of
those input fields (because they are inside a library and are used very
often). So I had to go along with Martin's suggestion. But anyway,
thanks for the quick reply!

Christian
 
>> Do I have to put the fields into a form and submit the whole form
>
> Wrapping all three inputs in a form with an AjaxFormSubmitBehavior is
> the easiest solution.
> Do you have any problems with it?
>
> Sven
>
>
>
> On 04/14/2014 07:45 PM, Christian Smolka wrote:
>> Hi to everybody!
>>
>> My little problem is about validating multiple input fields as a
>> single one.
>> So, I have three DoB fields (one for the day, one for the month and one
>> for the
>> year) that should be validated as a single date.
>>
>> While using Wicket 1.5 we overwrote
>> AjaxEventBehavior#getEventHandler() and
>> returned a custom made JavaScript that serialized the three fields like
>> this:
>>
>>
>> StringBuffer buffer = new StringBuffer("wicketAjaxPost('")
>>      .append(this.getCallbackUrl()).append("', ");
>> for (String id : this.getInputIds()) {
>>     
>> buffer.append("wicketSerialize(Wicket.$('").append(id).append("')) + ");
>> }
>> buffer.setLength(buffer.length() - 3);
>> return buffer;
>>
>>
>> This worked pretty well. But I have to migrate the application to
>> Wicket 6
>> and this doing does work anymore. As far as I understood the new
>> Ajax-way,
>> it isn't possible anymore to provide a custom script like the one
>> above. But
>> how can I restore the old behavior? Do I have to put the fields into a
>> form and
>> submit the whole form to validate it?
>>
>> Thanks in advance!
>>
>>
>> ---------------------------------------------------------------------
>> 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: Validating multiple components as one

Posted by Sven Meier <sv...@meiers.net>.
>Do I have to put the fields into a form and submit the whole form

Wrapping all three inputs in a form with an AjaxFormSubmitBehavior is the easiest solution.
Do you have any problems with it?

Sven



On 04/14/2014 07:45 PM, Christian Smolka wrote:
> Hi to everybody!
>
> My little problem is about validating multiple input fields as a single one.
> So, I have three DoB fields (one for the day, one for the month and one
> for the
> year) that should be validated as a single date.
>
> While using Wicket 1.5 we overwrote AjaxEventBehavior#getEventHandler() and
> returned a custom made JavaScript that serialized the three fields like
> this:
>
>
> StringBuffer buffer = new StringBuffer("wicketAjaxPost('")
>      .append(this.getCallbackUrl()).append("', ");
> for (String id : this.getInputIds()) {
>      buffer.append("wicketSerialize(Wicket.$('").append(id).append("')) + ");
> }
> buffer.setLength(buffer.length() - 3);
> return buffer;
>
>
> This worked pretty well. But I have to migrate the application to Wicket 6
> and this doing does work anymore. As far as I understood the new Ajax-way,
> it isn't possible anymore to provide a custom script like the one above. But
> how can I restore the old behavior? Do I have to put the fields into a
> form and
> submit the whole form to validate it?
>
> Thanks in advance!
>
>
> ---------------------------------------------------------------------
> 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