That is a very valid point! In fact, one of the FormComponents in our
form is broken now that way.

I did a patch for wicket 1.2 codebase and changed Form.ValidationVisitor
so that a child component is not processed if any of its parents are
disabled:

        private static abstract class ValidationVisitor implements
FormComponent.IVisitor
        {

                /**
                 * @see
wicket.markup.html.form.FormComponent.IVisitor#formComponent(wicket.markup.html.form.FormComponent)
                 */
                public void formComponent(FormComponent formComponent)
                {
                        if (formComponent.isVisibleInHierarchy() && 
formComponent.isValid()
                                        && formComponent.isEnabled() && 
formComponent.isEnableAllowed() 
                                        && formComponent.isEnabledInHierarchy())
                        {
                                validate(formComponent);
                        }
                }
}

This change would make it pretty easy to implement the form without
disablement/enablement problems.

Joni

On Tue, 2006-07-04 at 14:08 +0200, Johan Compagner wrote:
> in swing we also have our special EnablePanels so that the setEnable
> is also called on all the childs.
> But one problem with that.
> 
> If a child component was already disabled and then the parent first
> gets disabled and then enabled. 
> What should happen to that child?
> 
> johan
> 
> 
> On 7/4/06, Joni Freeman <[EMAIL PROTECTED]> wrote:
>         That's how I originally approached the issue. However, there's
>         two
>         problems.
>         
>         If I return false from isEnabled, the text fields etc. are
>         disabled when
>         they are rendered. Thus preventing the user from entering any
>         input. By
>         default, the checkboxes are not checked.
>         
>         The second issue is that isEnabled is not recursive. That is,
>         disabling 
>         of parent component does not disable child components. Some of
>         the
>         FormComponents in our form are very complex components.
>         
>         I guess that these issues could be solved by making a checkbox
>         to send
>         onSelectionChanged event (or perhaps by using AjaxCheckbox)
>         and 
>         disabling/enabling the target component (ant its child
>         components):
>         
>         public class CheckboxController extends CheckBox {
>             @Override
>             protected void onSelectionChanged(Object newSelection) {
>                 if ((Boolean) newSelection) { 
>                     toggleChildren(true);
>                 } else {
>                     toggleChildren(false);
>                 }
>             }
>         
>             private void toggleChildren(final boolean b) {
>                 target.visitChildren(new wicket.Component.IVisitor ()
>         {
>                     public Object component(final Component component)
>         {
>                         component.setEnabled(b);
>                         return
>         wicket.Component.IVisitor.CONTINUE_TRAVERSAL;
>                     }
>                 });
>             }
>         }
>         
>         BTW. Wouldn't it be logical if isEnabled were recursive? Or is
>         there
>         situations where parent component is disabled but some of its
>         children
>         are enabled?
>         
>         Joni
>         
>         On Mon, 2006-07-03 at 09:59 -0700, Eelco Hillenius wrote: 
>         > That all works only for validation - it doesn't prevent
>         components'
>         > models from being updated, and it is quite a lot of work. An
>         easier
>         > and better way is to override isEnabled (or isVisible, but
>         isEnabled 
>         > seems better here) and return false if they shouldn't be
>         validated and
>         > updated. The only catch there is that your checkboxes are
>         not yet
>         > updated either, so you'll need to call getInput (or
>         getInputAsArray) 
>         > on those checkboxes to get the posted value.
>         >
>         > Eelco
>         >
>         >
>         > On 7/3/06, Martijn Dashorst <[EMAIL PROTECTED]>
>         wrote:
>         > > 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
>         > >
>         >
>         > 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
> 
> 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

Reply via email to