Wicket in Action

Wicket HTML validator 1.2

09 June 2009, by dashorst

I just performed the 1.2 release of WicketStuff HTML Validator, thanks to Emond Papegaaij, a Topicus Onderwijs co-worker. This new release adds the ability to ignore Wicket specific bugs when using the & entity in JavaScript calls, and adds the ability to ignore <input type="text" autocomplete="false" /> validation errors. Even though you specify that your document is (X)HTML compliant, browsers will (fortunately) still work with these validation errors present.

The markup validator was featured in my presentation "Get your Wicket Application in production (and keep your weekends free)". The validator will notify you if you have invalid HTML markup in your rendered pages. While usually not destructive, having invalid markup can result in long debugging errors when replacing part of your page with for example Ajax, or traversing the DOM.

You can use it by adding the HtmlValidationResponseFilter to the Wicket
request cycle filters in the following fashion:

public class MyApplication extends WebApplication {
    // ...

    @Override
    protected void init() {
        // only enable the markup filter in DEVELOPMENT mode
        if(DEVELOPMENT.equals(getConfigurationType())) {
            HtmlValidationResponseFilter htmlvalidator = 
                              new HtmlValidationResponseFilter();
            htmlvalidator.setIgnoreAutocomplete(true);
            htmlvalidator.setIgnoreKnownWicketBugs(true);
            getRequestCycleSettings()
                .addResponseFilter(htmlvalidator);
        }
    }
}

And you’re all set. Make sure you define a XHTML doctype in your pages, such
as:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Foo</title>
</head>
<body>
</body>
</html>

To use the HtmlValidator, include the following in your project’s pom:

<dependency>
    <groupId>org.wicketstuff</groupId>
    <artifactId>htmlvalidator</artifactId>
    <version>1.2</version>
    <scope>test</scope>
</dependency>

You might need to add the Wicket Stuff maven repository to your repository list.

-->