You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martijn Dashorst <ma...@gmail.com> on 2010/12/08 17:28:50 UTC

HTML 5 and Wicket: configuration from markup?

In HTML 5 it is possible to use attributes like required, autocomplete
etc. Currently Wicket ignores such attributes and does not parse them
into anything meaningful, except IIRC the markup id.

What we could do is the following:

public class TextField ... {
	@Override
	protected void onInitialize()
	{
		super.onInitialize();
		setRequired(getMarkupAttributes().containsKey("required")));
                setEnabled(getMarkupAttributes().containsKey("enabled")));
	}
}

By doing this in onInitialize() we don't override anything done in
onConfigure, but we would negate anything set on the component prior
to it being added to the page. For example:

TextField tf = new TextField( ... );
tf.setRequired(false);
add(tf);

<input type="text" wicket:id="" required>

would ultimately result in a required field

Another thing is that if/when we allow this, the next thing folks want
is to make it conditional... and then we have Wicket JSPs...

So I'm not sure if it is a good idea to enable component configuration
from the markup.

Martijn

Re: HTML 5 and Wicket: configuration from markup?

Posted by Igor Vaynberg <ig...@gmail.com>.
it cannot be a setting on application level because it would break
component libraries.

-igor

On Wed, Dec 8, 2010 at 6:37 PM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> On Wed, Dec 8, 2010 at 10:28 AM, Martijn Dashorst
> <ma...@gmail.com> wrote:
>> In HTML 5 it is possible to use attributes like required, autocomplete
>> etc. Currently Wicket ignores such attributes and does not parse them
>> into anything meaningful, except IIRC the markup id.
>>
>> What we could do is the following:
>>
>> public class TextField ... {
>>        @Override
>>        protected void onInitialize()
>>        {
>>                super.onInitialize();
>>                setRequired(getMarkupAttributes().containsKey("required")));
>>                setEnabled(getMarkupAttributes().containsKey("enabled")));
>>        }
>> }
>>
>> By doing this in onInitialize() we don't override anything done in
>> onConfigure, but we would negate anything set on the component prior
>> to it being added to the page. For example:
>>
>> TextField tf = new TextField( ... );
>> tf.setRequired(false);
>> add(tf);
>>
>> <input type="text" wicket:id="" required>
>>
>> would ultimately result in a required field
>>
>> Another thing is that if/when we allow this, the next thing folks want
>> is to make it conditional... and then we have Wicket JSPs...
>>
>> So I'm not sure if it is a good idea to enable component configuration
>> from the markup.
>>
>> Martijn
>>
>
> Could we create an Html5AutoConfigurationBehavior that could be added
> to components if people wanted to auto-configure their components from
> markup?  We might even provide an icomponentinstantiationlistener to
> automagically add this to all components for users.  Or, make it a
> markup setting on the application.
>
> --
> Jeremy Thomerson
> http://wickettraining.com
> Need a CMS for Wicket?  Use Brix! http://brixcms.org
>

Re: HTML 5 and Wicket: configuration from markup?

Posted by Martin Grigorov <mg...@apache.org>.
On Thu, Dec 9, 2010 at 3:16 PM, Jeremy Thomerson
<je...@wickettraining.com>wrote:

> > 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.
>
Actually you can use
org.apache.wicket.behavior.Behavior.beforeRender(Component) instead.
All you need is component.getMarkupAttributes() and depending on them to add
some validators to the (form)component.

>
> 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...)
>

Here is another solution from me:
Add constructor parameter or setter to Form and FormComponent
(#setMarkupConfigurable(true)) and then the user can call that for each
formcomponent she wants or write a visitor that will do that for all
formcomponents in form/page, or component instantiation listener.
Using a constructor parameter will work if we want to configure from markup
in onInitialize(), using a setter will
move this logic to onConfigure()/onBeforeRender() and will require usage of
hasBeenRendered() == false.



> --
> Jeremy Thomerson
> http://wickettraining.com
> Need a CMS for Wicket?  Use Brix! http://brixcms.org
>

Re: HTML 5 and Wicket: configuration from markup?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
> 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

Re: HTML 5 and Wicket: configuration from markup?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Dec 8, 2010 at 10:44 AM, Martin Grigorov <mg...@apache.org> wrote:
>> Could we create an Html5AutoConfigurationBehavior that could be added
>> to components if people wanted to auto-configure their components from
>> markup?  We might even provide an icomponentinstantiationlistener to
>> automagically add this to all components for users.  Or, make it a
>> markup setting on the application.
>>
>> instanctiationlistener will not work because the markup is not available
> yet at construction time of FormComponent
> I like the idea with markupsettings

I didn't say "do the configuration in the instantiation listener".  I
said "automagically add this [AutoConfigureBehavior mentioned in
previous sentence] to all components".

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());
	}
}


-- 
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket?  Use Brix! http://brixcms.org

Re: HTML 5 and Wicket: configuration from markup?

Posted by Martin Grigorov <mg...@apache.org>.
On Wed, Dec 8, 2010 at 5:37 PM, Jeremy Thomerson
<je...@wickettraining.com>wrote:

> On Wed, Dec 8, 2010 at 10:28 AM, Martijn Dashorst
> <ma...@gmail.com> wrote:
> > In HTML 5 it is possible to use attributes like required, autocomplete
> > etc. Currently Wicket ignores such attributes and does not parse them
> > into anything meaningful, except IIRC the markup id.
> >
> > What we could do is the following:
> >
> > public class TextField ... {
> >        @Override
> >        protected void onInitialize()
> >        {
> >                super.onInitialize();
> >
>  setRequired(getMarkupAttributes().containsKey("required")));
> >                setEnabled(getMarkupAttributes().containsKey("enabled")));
> >        }
> > }
> >
> > By doing this in onInitialize() we don't override anything done in
> > onConfigure, but we would negate anything set on the component prior
> > to it being added to the page. For example:
> >
> > TextField tf = new TextField( ... );
> > tf.setRequired(false);
> > add(tf);
> >
> > <input type="text" wicket:id="" required>
> >
> > would ultimately result in a required field
> >
> > Another thing is that if/when we allow this, the next thing folks want
> > is to make it conditional... and then we have Wicket JSPs...
> >
> > So I'm not sure if it is a good idea to enable component configuration
> > from the markup.
> >
> > Martijn
> >
>
> Could we create an Html5AutoConfigurationBehavior that could be added
> to components if people wanted to auto-configure their components from
> markup?  We might even provide an icomponentinstantiationlistener to
> automagically add this to all components for users.  Or, make it a
> markup setting on the application.
>
> instanctiationlistener will not work because the markup is not available
yet at construction time of FormComponent
I like the idea with markupsettings

using getFlag() to check those two (required and enabled) will not work too
because the method returns boolean, there is no "unknown/unset" state

And I *don't* like the idea of Wicket JSP thingie. We can use the markup to
facilitate the configuration (i.e. save some boilerplate in .java) but not
for any logic

> --
> Jeremy Thomerson
> http://wickettraining.com
> Need a CMS for Wicket?  Use Brix! http://brixcms.org
>

Re: HTML 5 and Wicket: configuration from markup?

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Dec 8, 2010 at 10:28 AM, Martijn Dashorst
<ma...@gmail.com> wrote:
> In HTML 5 it is possible to use attributes like required, autocomplete
> etc. Currently Wicket ignores such attributes and does not parse them
> into anything meaningful, except IIRC the markup id.
>
> What we could do is the following:
>
> public class TextField ... {
>        @Override
>        protected void onInitialize()
>        {
>                super.onInitialize();
>                setRequired(getMarkupAttributes().containsKey("required")));
>                setEnabled(getMarkupAttributes().containsKey("enabled")));
>        }
> }
>
> By doing this in onInitialize() we don't override anything done in
> onConfigure, but we would negate anything set on the component prior
> to it being added to the page. For example:
>
> TextField tf = new TextField( ... );
> tf.setRequired(false);
> add(tf);
>
> <input type="text" wicket:id="" required>
>
> would ultimately result in a required field
>
> Another thing is that if/when we allow this, the next thing folks want
> is to make it conditional... and then we have Wicket JSPs...
>
> So I'm not sure if it is a good idea to enable component configuration
> from the markup.
>
> Martijn
>

Could we create an Html5AutoConfigurationBehavior that could be added
to components if people wanted to auto-configure their components from
markup?  We might even provide an icomponentinstantiationlistener to
automagically add this to all components for users.  Or, make it a
markup setting on the application.

-- 
Jeremy Thomerson
http://wickettraining.com
Need a CMS for Wicket?  Use Brix! http://brixcms.org

Re: HTML 5 and Wicket: configuration from markup?

Posted by andrea del bene <an...@libero.it>.
Well, if these markup attributes are part of HTML 5 standard I think 
that Wicket should support them somehow. But it would be useful if we 
could switch on/off this kind of configuration with a new method, like 
enableMarkupConfig(boolean enabled)
> In HTML 5 it is possible to use attributes like required, autocomplete
> etc. Currently Wicket ignores such attributes and does not parse them
> into anything meaningful, except IIRC the markup id.
>
> What we could do is the following:
>
> public class TextField ... {
> 	@Override
> 	protected void onInitialize()
> 	{
> 		super.onInitialize();
> 		setRequired(getMarkupAttributes().containsKey("required")));
>                  setEnabled(getMarkupAttributes().containsKey("enabled")));
> 	}
> }
>
> By doing this in onInitialize() we don't override anything done in
> onConfigure, but we would negate anything set on the component prior
> to it being added to the page. For example:
>
> TextField tf = new TextField( ... );
> tf.setRequired(false);
> add(tf);
>
> <input type="text" wicket:id="" required>
>
> would ultimately result in a required field
>
> Another thing is that if/when we allow this, the next thing folks want
> is to make it conditional... and then we have Wicket JSPs...
>
> So I'm not sure if it is a good idea to enable component configuration
> from the markup.
>
> Martijn
>