Why not something like:
class MyCustomValidator extends AbstractFormValidator {
private List<StringValidator> validators;
private CheckBox checkbox;
private FormComponent formComponent;
public MyCustomValidator(cb, fc, StringValidator... vs) {
this.checkbox = cb;
this.formComponent = fc;
this.validators = Arrays.asList(vs);
}
public boolean validate(Form form) {
if(checkbox.isChecked) {
for(StringValidator sv : validators) {
sv.onValidate(formComponent, formComponent.getInput());
}
}
}
}
Martijn
On 7/3/06, Joni Freeman <[EMAIL PROTECTED]> wrote:
> The problem with FormValidator is that the individual components
> (checkbox + textfields) are still validated with validators
> (FormComponent.validateValidators()). My client wants the form to work
> so that if the checkbox is not checked, the textfields can contain
> invalid data.
>
> One way to implement this could be by changing the execution order of
> validators so that FormValidators are executed before component
> validators:
>
> class MyForm extends Form {
> protected void validate()
> {
> validateRequired();
> validateConversion();
> validateFormValidators();
> validateValidators();
> }
> }
>
> And then somehow disable the component at special FormValidator if
> checkbox is not checked. Maybe this can be done by calling
> setEnabled(false) ?
>
> Joni
>
> On Mon, 2006-07-03 at 13:33 +0200, Martijn Dashorst wrote:
> > You can add form level validation, creating composite validators, and
> > add both the checkbox and the field, and the validators for the field
> > to your composite validator.
> >
> > See EqualInputValidator for an example implementation.
> >
> > Martijn
> >
> > On 7/3/06, Joni Freeman <[EMAIL PROTECTED]> wrote:
> > > I have a curious requirement for a form. When a user submits a form,
> > > some of the FormComponents should not be processed at all (for example,
> > > validation should not be done). Each FormComponent has an accompanying
> > > checkbox control which determines whether the actual control is
> > > activated or not.
> > >
> > > [ ] _______ (this text field should not be processed)
> > > [X] _______ (this should be)
> > >
> > > etc.
> > >
> > > One way to implement this could be by overriding Form.validate().
> > > However, it seems tedious and not very elegant, so maybe i'm missing
> > > something obvious?
> > >
> > > Joni
> > >
> > >
> > >
> > > Using Tomcat but need to do more? Need to support web services, security?
> > > Get stuff done quickly with pre-integrated technology to make your job
> > > easier
> > > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> > > _______________________________________________
> > > Wicket-user mailing list
> > > [email protected]
> > > https://lists.sourceforge.net/lists/listinfo/wicket-user
> > >
> >
> >
>
>
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
--
Download Wicket 1.2 now! Write Ajax applications without touching JavaScript!
-- http://wicketframework.org
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user