Wednesday, September 25, 2013

Wicket 6 - Disable Page Serialization

In some cases it makes sense to disable Page Serialization, this can be archived by registering empty Page Store:

public class WicketWebApplication extends WebApplication {

    @Override 
    public Class<? extends Page> getHomePage() {
        return CqlCommanderPage.class; 
    } 

    @Override 
    protected void init() {
        super.init(); 
        setPageManagerProvider(new NoSerializationPageManagerProvider(this));
    } 
}
public class NoSerializationPageManagerProvider extends DefaultPageManagerProvider {

    public NoSerializationPageManagerProvider(Application application) {
        super(application); 
    } 

    @Override 
    protected IPageStore newPageStore(IDataStore dataStore) { 
        return new IPageStore() {
            @Override 
            public void destroy() {
            } 

            @Override 
            public IManageablePage getPage(String sessionId, int pageId) {
                return null;
            } 

            @Override 
            public void removePage(String sessionId, int pageId) {
            } 

            @Override 
            public void storePage(String sessionId, IManageablePage page) {
            } 

            @Override 
            public void unbind(String sessionId) {
            } 

            @Override 
            public Serializable prepareForSerialization(String sessionId, Object page) {
                return null;
            } 

            @Override 
            public Object restoreAfterSerialization(Serializable serializable) {
                return null;
            } 

            @Override 
            public IManageablePage convertToPage(Object page) {
                return null;
            } 
        }; 

    } 
}

2 comments:

  1. What the real reasons for disabling page serialization?
    Why not to disable persistent page storage only?

    ReplyDelete
    Replies
    1. Well it depends on your usecase. I've had a page with mostly Ajax components and back-button support in browser in this case makes no sense so the whole serialization is not needed.

      Delete