There's already a feature request in jira for this:

https://issues.apache.org/jira/browse/WICKET-1469

I tried implementing it once, but I run into trouble with component
hierarchy. Only
allowing labels for sibling components would probably make the implementation
a lot easier, but I'm not sure if this a too big limitation to only
allow siblings.

Consider the situation when the input field and the label are in different table
cells, e.g.

<tr><td wicket:id=...><input  wicket:id=... .../></td><td
wicket:id=...><label  wicket:id=... .../></td></tr>

but you need to append some attributes to the td tags (e.g. for coloring).
If I understood correctly what you suggested, this usecase wouldn't be covered.

cheers,
Jonas



On Sun, Dec 13, 2009 at 2:06 PM, Erik van Oosten <e.vanoos...@grons.nl> wrote:
> Hi,
>
> In the many Wicket applications I have seen, the most frequent error is to
> not correctly set the 'for' attribute of an HTML 'label' element. Currently
> it is necessary to do this from code. Although a quickly written component
> will make this fairly easy, the task is occurring that often that imho
> better support by wicket is warranted.
>
> I therefore propose a new wicket:for attribute that looks as follows:
>
> <label *wicket:for="name"*>Name</label>
> <input wicket:id="name" type="text"/>
>
> The rendered markup could for example be:
>
> <label for="name78">Name</label>
> <input id="name78" name="name78" type="text" value="..."/>
>
> Some more thoughts on the design of the wicket:for attribute:
> - The value of the attribute refers to a component by component id. The
> referred component must be a sibling of the same container that provides the
> markup with the label element. Referring to a component outside this
> container is tricky as then component ids are no longer unique.
> - The wicket:for attribute will render the 'for' attribute with the markup
> id of the referenced component as value.
> - The method setOuputMarkupId(true) will be called on the referenced
> component.
>
> More ideas?
> If I would implement such a wicket:for attribute, would it be accepted in
> Wicket core?
>
> Regards,
>   Erik.
>
>
> --
> Erik van Oosten
> http://day-to-day-stuff.blogspot.com/
>
>
>

Reply via email to