> Similarly, the Length element can and probably should be using a
> StringValidator for a TextField and not setting maxlength. Maybe it
> should do both. ;-)
I've thought about using validators here and "ideally" would use a
StringValidatorWithBehavior that would automatically attach the markup
attributes.  any thoughts?

Yeah, something like that is now possible:

        private static class MaxLengthValidator extends
StringValidator.MaximumLengthValidator
                        implements
                                IBehaviorProvider
        {
                public MaxLengthValidator(int maximum)
                {
                        super(maximum);
                }

                /**
                 * @see 
org.apache.wicket.validation.IBehaviorProvider#newValidationBehavior(org.apache.wicket.Component)
                 */
                public IBehavior newValidationBehavior(Component component)
                {
                        if (component instanceof AbstractTextComponent)
                        {
                                return new SimpleAttributeModifier("maxlength",
String.valueOf(getMaximum()));
                        }
                        return null;
                }
        }

The API still is to be reviewed and tweaked, but this is the basic idea.

> It strikes me we probably need a:
>
> Hibernate Validator Attribute + Component type -> Validator mapping
>
> ...because what sort of validator you want to use will be dependent on
> the component type.

I actually think I would like to create a application component
listener for this (similar to the SpringBean component listener) so
that an entire application will "just work" and you don't have to
worry about manually adding validators at all.  thoughts?
Ryan

That's an interesting idea; might work out pretty cool. Best thing
again is to create a first pass and see how it works.

Any plans for creating an example application for this? If you ever
want this to get a good ammount of traction, it needs one.

Eelco

Reply via email to