The XHTML
label
is highly flexible, with the theoretical ability to appear anywhere within the same form as its associated form control:
UWC_TOKEN_START1160856267995UWC_TOKEN_END
Of course, theory tends to break down in practice. Screenreaders generally require the label to either enclose or be adjacent to the control, rather than wandering off on its own. In theory, wrapping a
label
round the control should implicitly associate the label with the control (as in the example code above). But, in practice, many user agents screenreaders still require the
for
attribute to recognise the association.
Still, some web designers have found wrapping controls in their
label
elements the best starting point for styling a form. Unfortunately, Wicket's
SimpleFormComponentLabel
cannot cope with that situation, since it replaces its entire body (including the control itself) with the label text defined in its model.
The solution is to use
FormComponentLabel
for adding the correct
id
to the label's
for
attribute, but add the actual text of the label in with other components – typically a
Label
bound to a
span
. For example, in the form in ExamplePage.html:
UWC_TOKEN_START1160856267996UWC_TOKEN_END
And in ExampleForm.java:
UWC_TOKEN_START1160856267997UWC_TOKEN_END