wicket

Page.setVersioned(false) but still serialized. Why?


I have single page application (all AJAX) and thus don't need page versioning. So I do setVersioned(false). However, the page is still serialized on each AJAX request and I would like to know why.

The Wicket version I use is: 7.6.0

WicketApplication.java

public class WicketApplication extends WebApplication {
    public Class<? extends WebPage> getHomePage() {
        return HomePage.class;
    }
    public void init() {
        super.init();
        getFrameworkSettings().setSerializer(new MySerizalizer("foo"));
        System.out.println("SERIALIZER: " + getFrameworkSettings().getSerializer().getClass().getName());
    }
    static class MySerizalizer extends org.apache.wicket.serialize.java.JavaSerializer {
        public MySerizalizer(String applicationKey) {
            super(applicationKey);
        }
        public byte[] serialize(Object object) {
            final byte[] serialize = super.serialize(object);
            System.out.println("serialized " + String.valueOf(serialize.length) + " bytes of " + object.getClass().getName());
            return serialize;
        }

    }
}

HomePage.java

public class HomePage extends WebPage {
    public HomePage() {
        final Label label = new Label("message", new PropertyModel<>(foo, "bar"));
        label.setOutputMarkupId(true);
        add(label);
        label.setVersioned(false);
        final AjaxLink<Foo> ajaxLink = new AjaxLink<Foo>("plus1") {
            public void onClick(AjaxRequestTarget target) {
                foo.inc();
                target.add(label);
            }
        };
        ajaxLink.setVersioned(false);
        add(ajaxLink);
        setVersioned(false);
        System.out.println("VERSIONED: " + isVersioned());
    }

    private Foo foo = new Foo();

    class Foo implements Serializable {
        int bar = 0;
        public String getBar() {
            return "bar is " + String.valueOf(bar);
        }
        public void inc() {
            bar += 1;
        }
    }
}

HomePage.html

<!DOCTYPE html>
<html>
    <body>
        <h1>home page</h1>
        <span wicket:id="message">Message goes here</span><br><br>
        <input type="button" wicket:id="plus1" value="add one"></input>
    </body>
</html>

Log:

SERIALIZER: com.foobar.WicketApplication$MySerizalizer
VERSIONED: false
serialized 2286 bytes of com.foobar.HomePage
serialized 2499 bytes of com.foobar.HomePage
serialized 2499 bytes of com.foobar.HomePage
serialized 2499 bytes of com.foobar.HomePage
serialized 2499 bytes of com.foobar.HomePage

For each click on the button (org.apache.wicket.ajax.markup.html.AjaxLink) the page gets serialized. Why if it is not versioned?


Solution

  • Only stateless pages are not stored. Page versioning is controlling whether a page instance could have several versions in the store.

    Since Wicket 7.4.0 it is possible to make the Ajax components and behaviors stateless too!