Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Introduction

All relevant Wicket tags and attributes must be in the wicket namespace, wicket:id="myLabel" or <wicket:panel>. Most browsers simply ignore HTML tags and attributes they don't know, which is why it doesn't harm that Wicket by default copies information into the HTML output generated. And it comes handy while tracing bugs.

However for the output to be HTML compliant, there must be a means to remove Wicket-specific information not relevant for the client browser from markup. XHTML shouldn't be a problem because all wicket-specific information is cleanly separated by using the wicket namespace, but not all browsers support XHTML well enough not to stumble over them.

Change to deployment mode

The simplest way to remove all wicket tags is to simply change your application from development mode to deployment mode. In your web.xml file, the following sets your application into development mode, which includes all wicket tags and provides an AJAX debugger.

No Format
<context-param>
    <param-name>configuration</param-name>
    <param-value>development</param-value>
</context-param>

The following sets your application into deployment mode, which removes all wicket tags.  It also removes the AJAX debugger.

No Format
<context-param>
    <param-name>configuration</param-name>
    <param-value>deployment</param-value>
</context-param>

See the Deployment FAQ for more details.

Strip Wicket tags in development mode

The solution is to call getMarkupSettings().setStripWicketTags(true) in the init method of your Application class. (Use getSettings().setStripWicketTags(true) for Wicket 1.1 and earlier.) This will remove from output all Wicket tags with Wicket namespace. That is, your output should not contain any tag like <wicket:panel> any more. It is off by default (not removing the tag). As these tags are not relevant for the client browser at all, I'd always keep it off during development and switch it on (remove them) for production sites.

In some cases you do not want the component's html to be wrapped by a div or span. In that case include a
<span wicket:id="myLabel">
as usual, but in java call setRenderBodyOnly(true) on the component. The span will be omitted from the output.

Remove wicket markup from a single page

In some situations during development, there may be some pages that should not include wicket tags in the output, but it is desired to have wicket tags on the remaining pages.  For instance, when creating a well formed XML document from Wicket, extra wicket tags and attribute markup can cause problems. One solution is to add the following to the page:

No Format
private boolean stripTags;

public TestPage() {
	stripTags =  Application.get().getMarkupSettings().getStripWicketTags();
}
@Override
protected void onBeforeRender() {
	Application.get().getMarkupSettings().setStripWicketTags(true);
}
@Override
protected void onAfterRender() {
	Application.get().getMarkupSettings().setStripWicketTags(stripTags);
}