elements:

Wicket Element - Radio Button and Label

In my Wicket app, I have a page with radio buttons and <label for="...">elements:

<input type="radio" wicket:id="today" id="today" />
<label for="today">Today</label>

However, while the property of the radio button identifier changes automatically, the for property of the tag tag remains unchanged and creates inconsistency (the tag is no longer associated with the button). What is the best way to solve this problem? Now I refer to this as follows:

add(
    new Label("todayLabel", "Today")
        .add(new AttributeModifier(
             "for",
             new Model<String>(today.getMarkupId()
 )));

but it is not very nice. Is there any other, clearer way to associate them with tags?

+3
source share
2 answers

Use FormComponentLabel :

add(new FormComponentLabel("todayLabel", today));
+4
source

You can do all this in markup:

<label wicket:for="today">
   <input type="radio" wicket:id="today" id="today" />
   Today
</label>

wicket html : https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html

+3

Source: https://habr.com/ru/post/1774051/


All Articles