[Drug XYZ]

How to add a component to a shortcut?

I have the following 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> 

But the shortcut cannot add a child component. Is there a way to achieve this html requirement?

This is the requirement of the designer:

Drug XYZ // shortcut
Information, price, other // span

+4
source share
2 answers

Make sure you use FormComponentLabel for the <label> element instead of Label .

Label The goal is to display text inside the associated element (it can be a <span> , <div> or almost any other tag).

FormComponentLabel The goal is to model a <label> . They receive the FormComponent with which they are associated, and automatically display the for attribute with the correct value for the dom id attribute.

Take a look at the Wicket wiki page for format control tags . They add components to FormComponentLabel there.

If you do not want to use FormComponentLabel , you should not specify the wicket:id attribute and manually set the DOM attribute id element that <label> will refer to. Then simply use it in the for <label> attribute.

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); 
+8
source

Using properties and <wicket:message>

The approach below is useful to me.
In my project, I have only one place on the page where the text for the <label> messages and verification is defined. This is the webpage properties file.

Additional <div> and their class attributes from 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> 

Java

 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 
+1
source

All Articles