The HTML documents that Wicket uses as templates can contain several special attributes and tags
...
To make most HTML editors not complain about using wicket tags and attributes, you need to declare the namespace. You can use any value for the namespace 'xmlns:wicket' but this value should be mapped in your HTML editor to one of the following definitions:
No Format |
---|
Wicket 1.5+ (XML Schema): http://git-wip-us.apache.org/repos/asf/wicket/repo?p=wicket.git;a=blob_plain;f=wicket-core/src/main/resources/META-INF/wicket-1.5.xsd;hb=master
Wicket 1.4 (DTD): http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd
Wicket 1.3 (DTD): http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd
Wicket 1.2 and earlier: http://wicket.sourceforge.net/
|
...
For example the first lines of a markup file could be:
Code Block |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" xml:lang="da" lang="da">
|
or
Code Block |
---|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"
xml:lang="en"
lang="en">
|
or
Code Block |
---|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:wicket="http://my.site.org">
|
...
wicket:id="ID_HERE" - Used on any element to which you want to add a component.
Code Block |
---|
|
<span wicket:id="hellotext">Hello</span>
|
The value of the attribute is duplicated in the java code:
Code Block |
---|
|
add(new Label("hellotext", "Hello World"));
|
...
wicket:message="attribute:resource_identifier" - Used on any tag that we want Wicket to provide an attribute with a value that's the result of a resource lookup.
Code Block |
---|
|
e.g. <input type="submit" wicket:message="value:page.search"/>
=> <input type="submit" value="Search Page""/>
|
Use comma separator if you have more than one attribute for internationalization:
Code Block |
---|
|
e.g. <img src="some.gif" wicket:message="alt:page.image.alt,title:page.image.title"/>
=> <img src="some.gif" alt="The Alt" title="The title"/>
|
Attribute wicket:enclosure
Code Block |
---|
|
<tr wicket:enclosure="">
|
The <tr> tag used in the example can be replaced with any html tag that can contain child elements. If the value of the attribute is empty it determines the wicket:id of the child component automatically by analyzing the wicket component (in this case only one wicket component is allowed) in between the open and close tags. If the enclosure tag has a non-empty value for wicket:enclosure attribute like
Code Block |
---|
|
<tr wicket:enclosure="controllingChildId">
|
...
Given markup like this:
Code Block |
---|
|
<label wicket:for="name"><wicket:label>Name</wicket:label>:</label><input wicket:id="name" type="text"/>
|
If the name component has its label set to 'First Name' the resulting output will be:
Code Block |
---|
|
<label for="name5">First Name:</label><input name="name" type="text" id="name5"/>
|
...
Example:
Code Block |
---|
|
<wicket:link><a href="Index.html" >Link to wicket document Index.html</a></wicket:link>
|
Now if you request Index.html it gets transformed to:
Code Block |
---|
|
<span><em>Link to wicket document Index.html</em></span>
|
If you want to change the markup to something else you can configure your wicket webapp in the init() method like
Code Block |
---|
|
getMarkupSettings().setDefaultBeforeDisabledLink("<bold>");
getMarkupSettings().setDefaultAfterDisabledLink("</bold>");
|
Which will result into to following:
Code Block |
---|
|
<span><bold>Link to wicket document Index.html</bold></span>
|
...
Example:
Code Block |
---|
|
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
PANEL CONTENT HERE
</wicket:panel>
</body>
</html>
|
...
<wicket:fragment> - is similar to <wicket:panel> but its is declared in the parent's markup instead of in a separate markup file.
Example:
Code Block |
---|
| html |
---|
| html |
---|
title | "MyPage.html"html |
---|
|
<html xmlns:wicket="http://wicket.apache.org">
<body>
<span wicket:id="panel1">panel</span>
<span wicket:id="panel2">panel</span>
<wicket:fragment wicket:id="frag1">This is the content of fragment 1</wicket:fragment>
<wicket:fragment wicket:id="frag2">fragment 2222222</wicket:fragment>
</body>
</html>
|
Code Block |
---|
| java |
---|
| java |
---|
title | "MyPage.java"java |
---|
|
public MyPage() {
Fragment panel1 = new Fragment("panel1", "frag1", MyPage.this);
add(panel1);
Fragment panel2 = new Fragment("panel2", "frag2", MyPage.this);
add(panel2);
}
|
...
<wicket:message> - Wicket will replace this with a string that is retrieved from a resource bundle. e.g.
Code Block |
---|
|
<wicket:message key="page.label">Default label</wicket:message>
|
Starting from Wicket 1.4 you can nest components within a wicket:message element. For example:
Code Block |
---|
|
<wicket:message key="myKey">
This text will be replaced with text from the properties file.
<span wicket:id="amount">[amount]</span>.
<a wicket:id="link">
<wicket:message key="linkText"/>
</a>
</wicket:message>
|
Code Block |
---|
myKey=Your balance is ${amount}. Click ${link} to view the details.
linkText=here
|
and
Code Block |
---|
|
add(new Label("amount",new Model("$5.00")));
add(new BookmarkablePageLink("link",DetailsPage.class));
|
...
<wicket:head> - Used for header contributions. Using this, panels, borders and child pages can add header sections to the pages they are place placed on. For instance:
Code Block |
---|
|
<wicket:head>
<script type="text/javascript">
function foo() {
alert("Hello, World!");
}
</script>
</wicket:head>
<wicket:panel>
<a href="#" onclick="foo();">Click me!</a>
</wicket:panel>
|
...
<wicket:enclosure>header-items/> - (since 16.15.0) A special placeholder tag that may be used to put all header contributions, either contributed from Java code or from <wicket:head>, in a predefined position in the page's <head> element.
Code Block |
---|
theme | Confluence |
---|
language | xml |
---|
title | <wicket:header-items> demo |
---|
|
<head>
<meta charset="utf-8">
<meta name="someKey" content="someValue">
<wicket:header-items/>
<title>My page title</title>
<link .../>
</head> |
With markup like this all header contributions done by using IHeaderResponse or via usage of <wicket:head> will be inserted between <meta name="someKey"> and <title> elements. This way the application developer can make sure that some head elements, like the special <meta charset="utf-8">, are always rendered before/after Wicket contributions.
Element wicket:enclosure
<wicket:enclosure> - (since 1.3) Useful for markup 3) Useful for markup whose visibility depends on visibility of surrounded component. Lets take a simple example where you want to show a table row, but only if a Label is visible.
Code Block |
---|
|
<tr><td class="label">Phone:</td><td><span wicket:id="phone">phone number</span></td></tr>
<wicket:enclosure>
<tr><td class="label">Fax:</td><td><span wicket:id="fax">fax number</span></td></tr>
</wicket:enclosure>
|
Code Block |
---|
|
add(new Label("fax") { public boolean isVisible() { return getModelObjectAsString()!=null; }});
|
...
If there is more than one wicket component directly underneath the enclosure, you have to specify which one controls the visibility by providing its id in the enclosure's child attribute:
Code Block |
---|
|
<wicket:enclosure child="address.street">
<tr>
<td class="label">Address:</td>
<td><span wicket:id="address.street"></span><span wicket:id="address.city"></span></td>
</tr>
</wicket:enclosure>
|
For nested children, specify the full path, separating them with ":", i.e.
Code Block |
---|
|
<wicket:enclosure child="users:fax">
<table wicket:id="users">
<tr><td class="label">Fax:</td><td><span wicket:id="fax">fax number</span></td></tr>
</table>
</wicket:enclosure>
|
...
<wicket:container> - Sometimes adding components in certain ways may lead to output of invalid markup. For example, lets pretend we output table rows two at a time using a repeater. The markup would look something like this:
Code Block |
---|
|
<table>
<span wicket:id="repeater">
<tr><td>...</td></tr>
<tr><td>...</td></tr>
</span>
</table>
|
Notice that we had to attach the repeater to a component tag - in this case a span, but a span is not a legal tag to nest under table. So we can rewrite the example as following:
Code Block |
---|
|
<table>
<wicket:container wicket:id="repeater">
<tr><td>...</td></tr>
<tr><td>...</td></tr>
</wicket:container>
</table>
|
...