Page without markup – Wicket in AppFuse – part 1

Posted: 2011-03-08 in Tricks & Tips
Tags: , ,

I am currently working on a Wicket frontend for AppFuse. I wanted to get know Wicket better and AppFuse seemed to be a good start to make some “real” application. Besides educational benefits for me it should be helpful for AppFuse and Wicket communities as well. In this and following post I will try to describe some of the problems I’ve met on my way.

Generally speaking every Wicket page has to have corresponding markup (html file with placed components). Without it MarkupNotFoundException is thrown in runtime. Implementing Wicket frontend in AppFuse I have found some pages which don’t have corresponding view (like logout or reload cache) and making an empty markup looked at least artificial for me. I tried to find some information how to avoid it, but the most interesting results were some old pages from mailing list archive with broken subsequential links. After some time I’ve dug out TextTemplate. It was the simplest class I’ve found that allows to dynamically generate markup for a Wicket page. It requires to override only two methods: getString() – which returns page template and interpolate() which allows to parametrize template (in our case does nothing). Because I needed only empty template a skeleton implementation was enough.

public class EmptyMarkup extends TextTemplate {

    public String getString() {
        return "";

    public TextTemplate interpolate(Map<String, Object> variables) {
        return this;

Wicket very often uses interfaces which indicate that given class has it own custom implementation of given feature. In case of dynamic markup IMarkupResourceStreamProvider was a key. Sample page with empty markup could look like:

public class NoMarkupPage extends WebPage implements IMarkupResourceStreamProvider {

//normal page implementation

    public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass) {
        return new EmptyMarkup();

It worked fine. It could be discussable if it’s worth to write new class and one additional method instead of the empty html file, but I’ve got to know some Wicket internals by the way of my digging and educational effect was achieved. Nevertheless I knew Wicket has some nice tricks, so a asked on the mailing list if there is a better way. The answer came very fast. Igor Vaynberg posted much more compact solution.

public class Logout extends WebPage {

    protected void onInitialize() {

        //some "business logic"

        //the key line
        throw new RestartResponseException(Login.class);
  1. […] application. Besides educational benefits for me it should be helpful for AppFuse and Wicket… [full post] emszpak Solid Soft tricks & tipsappfusetutorialwicket 0 0 0 […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s