wicket

How to disable page versioning in Apache Wicket 1.5? setVersioned(false) doesn't seem to be enough


I've been given this old Apache Wicket 1.5 web application.

All the URLs seem to end in ?xxx, where xxx is a number. This seems to be a Wicket "feature" that allows you to version / cache previously shown webpages. As nice as it might sound, in practical terms this is nothing more than a headache for all users involved, as even if the underlying data shown on the page changes and the user forces a page refresh, the old, stale page is still reloaded.

I've browsed online and in Wicket's docs it seems to be referred as "versioning".

I've tried to disable it by calling setVersioned(false) but it was of no avail -- I see no observable difference. Does anyone know how to get this to work?

Thanks


Solution

  • The problem is that your application caches the data into the models. In Wicket terminology this is called a static model.

    For example:

    Person person123 = personService.get(123);
    
    // a static model
    page.add(new Label("personMood", new Model(person123.getMood())));
    

    Here the Label will always show the mood of the person at the time of instantiation of the Label. The person may change his/her mood in the next second but the Label will still show the old/cached value.

    // a dynamic model
    page.add(new Label("personMood", new Model<String>() {
      @Override public String getObject() {
         return person123.getMood();
      }
    }));
    

    here the Label will render the current mood of the person at every render of this label/page.

    The pageId in the url tells Wicket which stateful page to lookup and load from the page store. Only stateful pages have such id. If you want to get rid of it then you should use only stateless components and behaviors in your page. There is wicket-devutils module which provides StatelessChecker to help you identify the reason when a Page becomes stateful by accident.

    In your case I am not sure which solution would be easier - to rework the Model(s) or to make the page stateless. Usually the first is easier.