如何将组件添加到标签?

时间:2012-06-14 15:58:03

标签: java html wicket wicket-1.5

我有以下html:

<label wicket:id="drugSearchResult.row.item.label" for="drug_1">[Drug XYZ]  
    <span wicket:id="drugSearchResult.row.item.info">[Information, Price, Other]</span>
</label>

但不允许label元素添加子组件。 有没有办法达到这个html要求?

这是设计师的要求:

  

药物XYZ // 标签
  信息,价格,其他// span

2 个答案:

答案 0 :(得分:8)

确保您使用FormComponentLabel代替<label>元素,而不是Label

Label的目的是在关联元素中输出文本(它可以是<span><div>或几乎任何其他标记。

FormComponentLabel的目的是对<label>标记进行建模。他们会收到与他们相关的FormComponent,并自动输出for属性,其中包含dom id属性的正确值。

查看Form control labels上的Wicket维基页面。他们正在向FormComponentLabel添加组件。

如果您想完全避免使用FormComponentLabel,则不应该为其提供wicket:id属性,并手动设置元素的DOM id属性{ {1}}将参考。然后,只需在<label>的{​​{1}}属性中使用它。

例如:

<强> HTML

for

<强>爪哇

<label>

答案 1 :(得分:1)

使用属性和<wicket:message>

对我来说,下面的方法很有用 在我的项目中,每页只有一个位置,其中定义了<label>和验证消息的文本。它是网页的属性文件。

其他<div>及其类属性来自Bootstrap。

<div class="form-group required">
    <label wicket:for="customer.name1">
        <wicket:message key="customer.name1"/>
    </label>
    <div class="controls">
        <input type="text" wicket:id="customer.name1" required class="form-control">
    </div>
</div>

爪哇

add(new RequiredTextField<String>("customer.name1")
         .setLabel(new StringResourceModel("customer.name1")));

customerPage.properties

# siehe wicket-core-7.9.0-sources.jar!/org/apache/wicket/Application_de.properties
Required='${label}' ist erforderlich
customer.name1=Name 1
customer.name2=Name 2
customer.department=Abteilung
customer.phone=Telefon
customer.active=aktiv