【问题标题】:Wicket - Radio Button and Label elementWicket - 单选按钮和标签元素
【发布时间】:2011-05-07 18:43:45
【问题描述】:

在我的 Wicket 应用中,我有一个带有单选按钮和 <label for="..."> 元素的页面:

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

但这不是很好。还有其他更清晰的方法可以将这些链接到标签吗?

【问题讨论】:

    标签: java radio-button wicket


    【解决方案1】:

    使用FormComponentLabel:

    add(new FormComponentLabel("todayLabel", today));
    

    【讨论】:

      【解决方案2】:

      您可以在标记中完成所有操作:

      <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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-16
        • 2015-11-17
        • 2021-07-27
        • 2013-06-16
        • 2013-03-18
        • 1970-01-01
        • 2021-01-20
        • 2021-04-23
        相关资源
        最近更新 更多