You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by splitshade <ma...@googlemail.com> on 2010/09/22 18:51:47 UTC

Inter-Component Validation (or how to marry two strangers)

Hi, 

this seems a rather simple question on the first sight, but I can't seem to
find a clean solution to this.

Image you have a Panel A that allows the User to input his Passport-Data,
further image you have another Panel B, that allows you to input the
Personal Data (like Birthday), now image you need to validate 
Passport-Data.
To Validate this, you need to know both Birthday (from Panel B) and the Data
from Panel A.

How to solve this Problem without Hacking around?
It seems clear, that a FormValidator is needed here... is it?

How should I validate two components, that do not know each other? Surely, I
could expose the inner components from Panel B and Panel A to a
FormValidator, OR ..

Everything looks like a Hack, is there a really clean way how to solve this
in Wicket?

Thanks in advance for ANY hints and help


-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Inter-Component-Validation-or-how-to-marry-two-strangers-tp2550675p2550675.html
Sent from the Users forum 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: Inter-Component Validation (or how to marry two strangers)

Posted by Michael O'Cleirigh <mi...@rivulet.ca>.
  Hi,

You could look at creating a custom subclass of FormComponentPanel that 
would contain both panel A and panel B.

Then for its validation you would process the checks that depend on the 
valid values from A and B.

This way you don't need any type of "hack" and the data is naturally 
available to the parent container component.

If there is an object R that contains the values from A and B you could 
put the logic in convertInput() like this:

MyFormComponentPanel<R>:

        protected void convertInput() {

         panelA.validate();
         panelB.validate();

         if (panelA.isValid() && panelB.isValid()) {
             R r = new R (panelA.getModelObject(), panelB.getModelObject())
             setConvertedInput(r);
        }

There are probably other options aswell.

Regards,

Mike



> this seems a rather simple question on the first sight, but I can't seem to
> find a clean solution to this.
>
> Image you have a Panel A that allows the User to input his Passport-Data,
> further image you have another Panel B, that allows you to input the
> Personal Data (like Birthday), now image you need to validate
> Passport-Data.
> To Validate this, you need to know both Birthday (from Panel B) and the Data
> from Panel A.
>
> How to solve this Problem without Hacking around?
> It seems clear, that a FormValidator is needed here... is it?
>
> How should I validate two components, that do not know each other? Surely, I
> could expose the inner components from Panel B and Panel A to a
> FormValidator, OR ..
>
> Everything looks like a Hack, is there a really clean way how to solve this
> in Wicket?
>
> Thanks in advance for ANY hints and help
>
>


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


Re: Inter-Component Validation (or how to marry two strangers)

Posted by splitshade <ma...@googlemail.com>.
Hi,

ok, that sounds pretty good...
If that is not uncommon to do, I'll try that.

I'm really impressed, how fast you helped me here, thank you very much!


-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Inter-Component-Validation-or-how-to-marry-two-strangers-tp2550675p2550817.html
Sent from the Users forum 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: Inter-Component Validation (or how to marry two strangers)

Posted by Igor Vaynberg <ig...@gmail.com>.
no, it is not that common because you still have not defined what the
"common" object that knows about both values is. usually this is the
model, and it is not that uncommon to do this:

new form() {
  onsubmit() {
        if (!getmodel().validate()) { error("something went bad"); }
  }
}

ie validate after the form has been submitted

-igor

On Wed, Sep 22, 2010 at 10:54 AM, splitshade
<ma...@googlemail.com> wrote:
>
> Hi again,
>
> well, i think the validator would be applied to the form, to which both
> panels are added, but you are right, there is nothing that is aware of both
> components (or more exactly on the inner components of the panels).
>
> Model-Validation sounds good, but the Model itself is updated after
> validation-phase,
> so propably i would need to implement further logic in updateModel().. or
> something.
>
> But I'm confused that there is no default way of handling such problems,
> this is a common use case, isn't it? Ok, not all too common, but possible.
>
> Thanks for your help!
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Inter-Component-Validation-or-how-to-marry-two-strangers-tp2550675p2550781.html
> Sent from the Users forum 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: Inter-Component Validation (or how to marry two strangers)

Posted by splitshade <ma...@googlemail.com>.
Hi again,

well, i think the validator would be applied to the form, to which both
panels are added, but you are right, there is nothing that is aware of both
components (or more exactly on the inner components of the panels).

Model-Validation sounds good, but the Model itself is updated after
validation-phase,
so propably i would need to implement further logic in updateModel().. or
something.

But I'm confused that there is no default way of handling such problems,
this is a common use case, isn't it? Ok, not all too common, but possible.

Thanks for your help!
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Inter-Component-Validation-or-how-to-marry-two-strangers-tp2550675p2550781.html
Sent from the Users forum 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: Inter-Component Validation (or how to marry two strangers)

Posted by Igor Vaynberg <ig...@gmail.com>.
validator on which field? or on a form? in either case something has
to be aware of both fields. a clean way may be to let your data model
validate itself for consistency and propagate any exceptions to the ui
layer as errors.

-igor

On Wed, Sep 22, 2010 at 10:34 AM, splitshade
<ma...@googlemail.com> wrote:
>
> Hi,
>
> thanks for the reply,
> well.. good question, this would propably be the validator, i need to check
> the validity of the personal data fields before the form gets submitted.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Inter-Component-Validation-or-how-to-marry-two-strangers-tp2550675p2550735.html
> Sent from the Users forum 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: Inter-Component Validation (or how to marry two strangers)

Posted by splitshade <ma...@googlemail.com>.
Hi,

thanks for the reply,
well.. good question, this would propably be the validator, i need to check
the validity of the personal data fields before the form gets submitted.

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Inter-Component-Validation-or-how-to-marry-two-strangers-tp2550675p2550735.html
Sent from the Users forum 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: Inter-Component Validation (or how to marry two strangers)

Posted by Igor Vaynberg <ig...@gmail.com>.
"something" has to know that both fields are related, so what is that
in your code?

-igor

On Wed, Sep 22, 2010 at 9:51 AM, splitshade
<ma...@googlemail.com> wrote:
>
> Hi,
>
> this seems a rather simple question on the first sight, but I can't seem to
> find a clean solution to this.
>
> Image you have a Panel A that allows the User to input his Passport-Data,
> further image you have another Panel B, that allows you to input the
> Personal Data (like Birthday), now image you need to validate
> Passport-Data.
> To Validate this, you need to know both Birthday (from Panel B) and the Data
> from Panel A.
>
> How to solve this Problem without Hacking around?
> It seems clear, that a FormValidator is needed here... is it?
>
> How should I validate two components, that do not know each other? Surely, I
> could expose the inner components from Panel B and Panel A to a
> FormValidator, OR ..
>
> Everything looks like a Hack, is there a really clean way how to solve this
> in Wicket?
>
> Thanks in advance for ANY hints and help
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Inter-Component-Validation-or-how-to-marry-two-strangers-tp2550675p2550675.html
> Sent from the Users forum 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: Inter-Component Validation (or how to marry two strangers)

Posted by nino martinez wael <ni...@gmail.com>.
I had something similar, I can look it up tomorrow(in 15 hours or so).
I think it was something like making the validators aware of each
other or something.



2010/9/22 splitshade <ma...@googlemail.com>:
>
> Hi,
>
> this seems a rather simple question on the first sight, but I can't seem to
> find a clean solution to this.
>
> Image you have a Panel A that allows the User to input his Passport-Data,
> further image you have another Panel B, that allows you to input the
> Personal Data (like Birthday), now image you need to validate
> Passport-Data.
> To Validate this, you need to know both Birthday (from Panel B) and the Data
> from Panel A.
>
> How to solve this Problem without Hacking around?
> It seems clear, that a FormValidator is needed here... is it?
>
> How should I validate two components, that do not know each other? Surely, I
> could expose the inner components from Panel B and Panel A to a
> FormValidator, OR ..
>
> Everything looks like a Hack, is there a really clean way how to solve this
> in Wicket?
>
> Thanks in advance for ANY hints and help
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Inter-Component-Validation-or-how-to-marry-two-strangers-tp2550675p2550675.html
> Sent from the Users forum 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