4

我有以下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>

但是标签元素不允许添加子组件。有什么办法可以实现这个 html 要求?

这是设计师的要求:

Drug XYZ //标签
信息、价格、其他 //跨度

4

2 回答 2

8

Make sure you're using FormComponentLabel for the <label> element instead of Label.

Label's purpose is to output text inside the associated element (it can be a <span>, <div> or almost any other tag).

FormComponentLabel's purpose is to model <label> tags. They receive the FormComponent they're related to and automatically output the for attribute with the proper value for the dom id attribute.

Take a look at the Wicket wiki page on Form control labels. They're adding components to FormComponentLabel there.

If you'd like to avoid using FormComponentLabel at all, you shouldn't be giving it a wicket:id attribute, and manually set the DOM id attribute of the element the <label> is going to refer to. Then just use it in the for attribute of the <label>.

For instance:

HTML

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

Java

TextField drug = new TextField("drug");
drug.setMarkupId("drug_1"); // Make sure this ID is unique in the page!
drug.setOutputMarkupId(true);
add(drug);
Label drugDescription = new Label("drugSearchResult.row.item.label", aModel);
add(drugDescription);
于 2012-06-14T19:46:25.500 回答
1

使用属性和<wicket:message>

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

附加<div>的 s 及其类属性来自 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
于 2018-01-05T08:27:18.747 回答