Wicket - 单选按钮和标签元素
在我的 Wicket 应用程序中,我有一个包含单选按钮和 元素的页面:
<input type="radio" wicket:id="today" id="today" />
<label for="today">Today</label>
但是,虽然单选按钮的 id 属性会自动更改,但 for 属性标签标记保持不变,这会造成不一致(标签不再链接到按钮)。解决这个问题的最佳方法是什么?现在,我这样解决这个问题:
add(
new Label("todayLabel", "Today")
.add(new AttributeModifier(
"for",
new Model<String>(today.getMarkupId()
)));
但这不太好。是否有另一种更清晰的方法将它们链接到标签?
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 radio button's id property gets changed automatically, the for property of the label tag stays the same and that creates an inconsistency (the label isn't linked to the button anymore). What's the best way to address this? Right now, I address it this way:
add(
new Label("todayLabel", "Today")
.add(new AttributeModifier(
"for",
new Model<String>(today.getMarkupId()
)));
but that's not very nice. Is there another, clearer way to link these to tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 FormComponentLabel:
Use FormComponentLabel:
您可以在标记中完成这一切:
有关 wicket html 标记的更多信息,请参见:https:// /cwiki.apache.org/WICKET/wickets-xhtml-tags.html
You can do it all in the markup:
More about wicket's html tags here: https://cwiki.apache.org/WICKET/wickets-xhtml-tags.html