Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevelmaxLevel32

The HTML documents that Wicket uses as templates can contain several special attributes and tags

Using Wicket Tags

To make most HTML editors not complain about using wicket tags and attributes, you need to declare the namespace:

...

If your IDE needs a DTD, you can find one in svn: http://svn.apache.org/repos/asf/wicket/trunk/jdk-1.4/wicket/wicket-xhtml1-strict.dtd

Wicket Attributes

Attribute wicket:id

wicket:id="ID_HERE" - Used on any tag that we want Wicket to replace.

Code Block
html
html

<span wicket:id="hellotext">Hello World</span>

Attribute wicket:message

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
html
html

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
html
html

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"/>

Wicket Tags

<wicket:link> - Support for wicket autolink functionality. Normally, you need to add a model (for example, a BookmarkablePageLink) for each link that Wicket manages. Using the wicket:link tag will automatically do this in the background for you.

...

Example:

Code Block
html
html

<wicket:link><a href="Index.html" >Link to wicket document Index.html</a></wicket:link>

Element wicket:panel

<wicket:panel> - The wicket:panel tag surrounds a component. This lets you wrap the component with HTML and BODY tags (so it can be displyed in a browser) but, when you include it, only the content inside the wicket:panel tag is actually included.

Example:

Code Block
html
html
Example:
    <html xmlns:wicket="http://wicket.sourceforge.net/">
      <body>
        <wicket:panel>
          PANEL CONTENT HERE
        </wicket:panel>
      </body>
    </html>

Element wicket:border and wicket:body

<wicket:border> and <wicket:body> - (I think this is the same as wicket:panel, except a border is drawn by default; verify).

Element wicket:extend

<wicket:extend> - Extend the markup of the superclass with this content.

Element wicket:child

<wicket:child> - Wicket will remove this content with the markup of the derived component (see <wicket:extend>)

Element wicket:message

<wicket:message> - Wicket will replace this with a string that is retrieved from a resource bundle. e.g.

Code Block
xml
xml

<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
xml
xml

<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
java
java

add(new Label("amount",new Model("$5.00")));
add(new BookmarkablePageLink("link",DetailsPage.class)); 

Results in:

Code Block
html
html
Your balance is $5.00. Click <a href="...">here</a> to view the details.

Element wicket:remove

<wicket:remove> - Wicket will remove this content in the final markup. This is useful for when you want your web designer to be able to show repeated content when they're working on it, but you want to generate at content using a ListView (or other loop).

Element wicket:head

<wicket:head>* - Used for header contributions. Using this, panels can add header sections to the pages they are place on. For instance:

Code Block
xml
xml
<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>

Element wicket:component

<wicket:component> - Creates a Wicket component on the fly. Needs a class attribute. Though this has been in wicket for a long time, it is still kind of an unsupported feature, as most of the core developers believe that this may lead to misuse of the framework. Before heavily relying on this feature, you might want to contact the user list to discuss alternative strategies. (THIS TAG IS NOT SUPPORTED BY THE CORE TEAM)

Element wicket:enclosure

<wicket:enclosure> - (since 1.3) This tag is useful for filtering markup that surrounds a component but has its visibility dependent on the visibility of that component. Lets take a simple example of where you want to show a table row, but only if a Label is visible.

Code Block
xml
xml

<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
java
java

add(new Label("fax") { public boolean isVisible() { return getModelObjectAsString()!=null; }});

If the label is not visible then neither is the contents of the enclosure. Without the enclosure you would have to add an extra WebMarkupContainer to your code and attach it to the tr tag then link its visibility to that of the label, with wicket:enclosure it is much simpler.

If there are more then one wicket components 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
xml
xml
<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>

Element wicket:container

<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
xml
xml

<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
xml
xml
<table>
 		<wicket:container wicket:id="repeater">
			<tr><td>...</td></tr>
 			<tr><td>...</td></tr>
 		</wicket:container>
 	</table>

...