> Example:
>
> class AutoConfigureBehavior extends AbstractBehavior {
> �...@override
> public void onComponentTag(Component component, ComponentTag tag) {
> super.onComponentTag(component, tag);
>
> if (component instanceof FormComponent<?> &&
> !Strings.isEmpty(tag.getAttribute("required"))) {
> ((FormComponent) component).setRequired(true);
> }
> }
> }
>
> class AddAutoConfigureBehaviorToAllComponents implements
> IComponentInstantiationListener {
> �...@override
> public void onInstantiation(Component component) {
> component.add(new AutoConfigureBehavior());
> }
> }
Wasn't thinking this all the way through yesterday. onComponentTag
won't work since you can't change the hierarchy at that point (IRRC
this will block additions to validators, and it should block the
change of the required flag). So, here's another idea.
In the application, you could have a factory method like
newComponentAutoConfigurer that returns an interface. Default could
either be returns one that does nothing or one that does the default
validation (required, min, max, etc). It could use an
IComponentOnBeforeRenderListener registered to the application to
invoke itself. It could have a method that allows the "configurers"
to be plugged in (i.e., in my app, I want designers to be able to
specify required in markup, but not min, max, etc...)
--
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket? Use Brix! http://brixcms.org