RE: Conditional validation without overriding isRequired

2012-06-06 Thread Schlärmann , Bob
Thanks for all the comments.

I'm implementing the conditional validation using a custom form processing 
method as suggested by Andrea. 

It's implemented as a form and behavior subclass. The overridden Form#process() 
first visits all form components and executes a special method on the behavior. 
The behavior then calls validate() on the source field and sets the required 
flag of the target component based on the converted input value.

The call to validate() is needed in order to have the converted input value set.

Best regards,

Bob

> You have to use the input or converted input of the field. See
> 
> https://cwiki.apache.org/WICKET/conditional-validation.html
> 
> for inspirations.
> 
> Sven
> 
> "Schlärmann, Bob"  schrieb:
> 
> >Thanks for your reply,
> >
> >> Argh, confused setVisible() with setRequired, my bad ;-)
> >> But nevertheless: call setRequiered(condition) in onConfigure().
> >
> >I've tried this but if I am correct isRequired() gets called before
> onConfigure() during the request cycle (at least this is the behaviour I see
> during debugging).
> >
> >The problem is that the user is then able to submit the form without filling
> in the required field if validation completely succeeds at once. Also the
> required fields "lag" behind one request cycle.
> >
> >
> >>
> >>-Tom
> >>
> >>
> >> Thomas Götz wrote:
> >>
> >> > Yes, you can also push the state instead of pulling it, which besides is
> >> preferrable in terms of efficiency (as onConfigure() is only called once
> per
> >> request whereas isVisible() is potentially called many time):
> >> >
> >> > TextField textField = new TextField("textField") {
> >> >@Override
> >> >protected void onConfigure() {
> >> >super.onConfigure();
> >> >setVisible(condition);
> >> >}
> >> > };
> >> >
> >> > You can also call textField.setVisible(...) in the Page's or Panel's
> >> onConfigure(), but then you need a reference to the textField (property of
> the
> >> page or panel). Or - if possible - you can group your FormComponents into a
> >> WebMarkupContainer an set the visibility there.
> >> >
> >> >   -Tom
> >>
> >>
> >> -
> >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> >> For additional commands, e-mail: users-h...@wicket.apache.org
> >>
> >
> >
> >Think green - keep it on the screen.
> >
> >This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be copied,
> disclosed to, retained or used by, any other party. If you are not an intended
> recipient then please promptly delete this e-mail and any attachment and all
> copies and inform the sender. Thank you.
> >
> >
> >
> >-
> >To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> >For additional commands, e-mail: users-h...@wicket.apache.org
> >

Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



RE: Conditional validation without overriding isRequired

2012-06-06 Thread Sven Meier
You have to use the input or converted input of the field. See

https://cwiki.apache.org/WICKET/conditional-validation.html

for inspirations.

Sven

"Schlärmann, Bob"  schrieb:

>Thanks for your reply,
>
>> Argh, confused setVisible() with setRequired, my bad ;-)
>> But nevertheless: call setRequiered(condition) in onConfigure().
>
>I've tried this but if I am correct isRequired() gets called before 
>onConfigure() during the request cycle (at least this is the behaviour I see 
>during debugging). 
>
>The problem is that the user is then able to submit the form without filling 
>in the required field if validation completely succeeds at once. Also the 
>required fields "lag" behind one request cycle.
>
>
>> 
>>-Tom
>> 
>> 
>> Thomas Götz wrote:
>> 
>> > Yes, you can also push the state instead of pulling it, which besides is
>> preferrable in terms of efficiency (as onConfigure() is only called once per
>> request whereas isVisible() is potentially called many time):
>> >
>> > TextField textField = new TextField("textField") {
>> >@Override
>> >protected void onConfigure() {
>> >super.onConfigure();
>> >setVisible(condition);
>> >}
>> > };
>> >
>> > You can also call textField.setVisible(...) in the Page's or Panel's
>> onConfigure(), but then you need a reference to the textField (property of 
>> the
>> page or panel). Or - if possible - you can group your FormComponents into a
>> WebMarkupContainer an set the visibility there.
>> >
>> >   -Tom
>> 
>> 
>> -
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
>
>
>Think green - keep it on the screen.
>
>This e-mail and any attachment is for authorised use by the intended 
>recipient(s) only. It may contain proprietary material, confidential 
>information and/or be subject to legal privilege. It should not be copied, 
>disclosed to, retained or used by, any other party. If you are not an intended 
>recipient then please promptly delete this e-mail and any attachment and all 
>copies and inform the sender. Thank you.
>
>
>
>-
>To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>For additional commands, e-mail: users-h...@wicket.apache.org
>


Re: Conditional validation without overriding isRequired

2012-06-06 Thread Andrea Del Bene

Hi,

you can consider to override form's process() method. Before calling the 
super version you can check for the radio value and set the other fields 
as required if the specific value was chosen.

Thanks for your reply,


Argh, confused setVisible() with setRequired, my bad ;-)
But nevertheless: call setRequiered(condition) in onConfigure().

I've tried this but if I am correct isRequired() gets called before 
onConfigure() during the request cycle (at least this is the behaviour I see 
during debugging).

The problem is that the user is then able to submit the form without filling in the 
required field if validation completely succeeds at once. Also the required fields 
"lag" behind one request cycle.



-Tom


Thomas Götz wrote:


Yes, you can also push the state instead of pulling it, which besides is

preferrable in terms of efficiency (as onConfigure() is only called once per
request whereas isVisible() is potentially called many time):

TextField  textField = new TextField("textField") {
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(condition);
}
};

You can also call textField.setVisible(...) in the Page's or Panel's

onConfigure(), but then you need a reference to the textField (property of the
page or panel). Or - if possible - you can group your FormComponents into a
WebMarkupContainer an set the visibility there.

   -Tom


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



Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



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




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



RE: Conditional validation without overriding isRequired

2012-06-06 Thread Schlärmann , Bob
Thanks for your reply,

> Argh, confused setVisible() with setRequired, my bad ;-)
> But nevertheless: call setRequiered(condition) in onConfigure().

I've tried this but if I am correct isRequired() gets called before 
onConfigure() during the request cycle (at least this is the behaviour I see 
during debugging). 

The problem is that the user is then able to submit the form without filling in 
the required field if validation completely succeeds at once. Also the required 
fields "lag" behind one request cycle.


> 
>-Tom
> 
> 
> Thomas Götz wrote:
> 
> > Yes, you can also push the state instead of pulling it, which besides is
> preferrable in terms of efficiency (as onConfigure() is only called once per
> request whereas isVisible() is potentially called many time):
> >
> > TextField textField = new TextField("textField") {
> >@Override
> >protected void onConfigure() {
> >super.onConfigure();
> >setVisible(condition);
> >}
> > };
> >
> > You can also call textField.setVisible(...) in the Page's or Panel's
> onConfigure(), but then you need a reference to the textField (property of the
> page or panel). Or - if possible - you can group your FormComponents into a
> WebMarkupContainer an set the visibility there.
> >
> >   -Tom
> 
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



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



Re: Conditional validation without overriding isRequired

2012-06-05 Thread Thomas Götz
Argh, confused setVisible() with setRequired, my bad ;-)
But nevertheless: call setRequiered(condition) in onConfigure().

   -Tom 


Thomas Götz wrote:

> Yes, you can also push the state instead of pulling it, which besides is 
> preferrable in terms of efficiency (as onConfigure() is only called once per 
> request whereas isVisible() is potentially called many time):
> 
> TextField textField = new TextField("textField") {
>@Override
>protected void onConfigure() {
>super.onConfigure();
>setVisible(condition);
>}
> };
> 
> You can also call textField.setVisible(...) in the Page's or Panel's 
> onConfigure(), but then you need a reference to the textField (property of 
> the page or panel). Or - if possible - you can group your FormComponents into 
> a WebMarkupContainer an set the visibility there.
> 
>   -Tom


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



Re: Conditional validation without overriding isRequired

2012-06-05 Thread Thomas Götz
Yes, you can also push the state instead of pulling it, which besides is 
preferrable in terms of efficiency (as onConfigure() is only called once per 
request whereas isVisible() is potentially called many time):

TextField textField = new TextField("textField") {
@Override
protected void onConfigure() {
super.onConfigure();
setVisible(condition);
}
};

You can also call textField.setVisible(...) in the Page's or Panel's 
onConfigure(), but then you need a reference to the textField (property of the 
page or panel). Or - if possible - you can group your FormComponents into a 
WebMarkupContainer an set the visibility there.

   -Tom



On 05.06.2012 at 16:51 Bob Schlärmann wrote:

> Hello,
> 
> A question about form processing: is it possible to do conditional form 
> validation without overriding FormComponent#isRequired?
> 
> I have a form with about 5 different form components (e.g. textfields, 
> dropdown, radiobutton). These fields are only required if a RadioGroup has a 
> certain value.
> 
> I've read the solution given in 
> https://cwiki.apache.org/WICKET/conditional-validation.html. But this means I 
> have to subclass all form components  and override isRequired. Is there an 
> easier solution?
> 
> Currently I'm using an Ajax call and disable the container of the optional 
> components, however that doesn't work if Javascript is disabled (also not 
> safe presumably).
> 
> Best regards,
> 
> Bob


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