Component Reference

A comprehensive list of Apache Wicket's components.

Labels

With Label components you can display dynamic text in your pages and components.

add(new Label<String>("text", "Hello, World!"));

Like all Wicket components, the label needs a counterpart in the markup with the same wicket:id:

<span wicket:id="text">gets replaced</span>

Using models you can display fields from your entities in your pages:

Person person = ...;
add(new Label<String>("text",
        new PropertyModel<String>(person, "name")));

Multi-line text

HTML notoriously strips newlines from your text and renders everything like it is just one line of text. With MultiLineLabel you can render text like it is supposed to look with paragraphs and line-breaks.

add(new Label("txt", "Hello,\nWorld!"));
add(new MultiLineLabel("multi", "Hello,\nWorld!"));

Will render the following markup:

<p>Hello,
World!</p>
<p>Hello,<br />World!</p>

And that will result in text like:

Hello, World!
Hello,
World!

Notice that the first label is displayed on a single line, while the MultiLineLabel correctly renders the text across multiple lines.

Label tags

The associated markup tag can be anything: a <span>, <a>nchor, <p>aragraph, or even if you don't want a surrounding tag in the final markup a <wicket:container>. So for example:

<span wicket:id="t1"></span>
<p wicket:id="t2"></p>
<wicket:container wicket:id="t3"></wicket:container>

Will render as:

<span>Hello, World!</span>
<p>Hello, World!</p>
Hello, World!

You can also use label.setRenderBodyOnly(true) to instruct Wicket to just render the body.

Escaping markup

By default, Wicket escapes all rendered text, preventing JavaScript injection attacks:

add(new Label("bad", 
      "<a onclick=\"alert('Booh')\">Click me</a>"));
					

Will render safely as the following markup:

&lt;a onclick=\&quot;alert(&#x27;Booh&#x27;)\&quot;&gt;Click me&lt;/a&gt;

Which displays in the browser as:

<a onclick=\"alert('Booh')\">Click me</a>