4

We've been using Wicket 1.3.7 for a few years now and are currently in the process of upgrading our project to wicket 6.x

I did a lot of research regarding to the page version parameters (e.g. ?1) being append to every URL, and how to get rid of them. (Could not find detailed information on this in the official documentation, unfortunately.) While doing so I read a lot of statements (from Wicket developers and users like

It is needed to keep track of the page version, otherwise it would not be possible to be stateful

and

You need to make your pages stateless to get rid of it

It was also suggested to use a custom implementation of AbstractComponentMapper, overriding encodePageComponentInfo not appending the parameter. Which has the obvious disadvantage of breaking statefulness for the mounted page. (see this SO answer for example)

Yesterday I stumbled upon RenderStrategy.ONE_PASS_RENDER.

I gave it a try, and after doing some testing I have got the impression that this is the setting to "restore the old wicket way": the page version parameters are gone, yet my pages are stateful.

Okay, there's a drawback, too. If have to take care of the double-submit problem myself, but I can live with that.

Question: are there any other drawbacks I am not (yet) aware of? Any surprises to be expected?

It seems to be the perfect solution, I just wondered why there are so many discussion about how to get rid of these parameter, even with wicket developers, where this is not suggested....

Thanks in advance.

Community
  • 1
  • 1
peterp
  • 3,101
  • 3
  • 22
  • 37

1 Answers1

5

We went through a similar upgrade path and my first reaction after upgrading was "Woah, these are some nasty URLs...".

Initially, we also switched to the one-pass render to have nicer URLs. But then after looking more into it, it appeared that the "?id" does more than just solve the double-sumbit problem.

Pages with Ajax components can be heavily stateful: as the user interacts with the page, you add components, remove others, etc. With the page ID in the URL parameters, you get back the page in the same state as you left it if you refresh the page (F5) or navigate to another page, then press the back button.

You lose that feature if you switch to one pass rendering since there is no way for the browser to identify which page from the page store is targeted and usually end up with another instance of the page object.

This was especially visible in "listing result" pages (pages that show a list/table of "items" with Ajax paging and filtering). On such pages with the one pass rendering, you'd often lose your search criteria or be brought back to the beginning of the results even though you had clicked "next page" a couple times.

We ended up using the "standard" rendering mechanism (not the one pass redering). URLs don't look so good but we felt the pros outweigh the cons (and the href do look OK, it's only the browser URL bar).

Another concern was the "crawlability" of our site. In order not to have the the 302s or the "url?id" impacting the Google index we added the following code in our Wicket application init method to force one-pass render for the Google Bot:

    setPageRendererProvider(new IPageRendererProvider() {
        @Override
        public PageRenderer get(RenderPageRequestHandler handler) {
            return new WebPageRenderer(handler) {
                @Override
                protected boolean isOnePassRender() {
                    // To avoid 302s with Google Bot and have good SEO.
                    String userAgent = ((HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest()).getHeader("User-Agent");
                    if (StringUtils.contains(userAgent, "Googlebot")) {
                        return true;
                    } else {
                        return super.isOnePassRender();
                    }
                }
            };
        }
    });
Christophe L
  • 13,725
  • 6
  • 33
  • 33
  • Thanks for sharing your experiences with this. What you describe sounds pretty much like what we are used to from Wicket 1.3. Personally, I like the idea of getting a freshly constructed page when hitting F5 :) If I need to preserve Ajax state, I'd rather encode it into the URL restfully. – peterp Feb 01 '13 at 08:35
  • Btw: from a SEO point of view, what's bothering me much more than the additional parameter (which I could probably handle fine using a [canonical tag](http://support.google.com/webmasters/bin/answer.py?hl=en&answer=139394)), is the fact that every page request immediately responds with a 302-redirect having the parameter appended. AFAIK, having 302 redirect with every request, for any URL is a really bad thing if you want to have your pages correctly crawled, indexed and good ranked. – peterp Feb 01 '13 at 08:40
  • 1
    Ah yes, the Google crawler! We had to add a little bit of code to force the one-pass render specifically for it. I updated my answer accordingly. – Christophe L Feb 01 '13 at 17:54
  • Thanks, good to know that it's possible to switch from ONE_PASS_RENDER within the application :) I think we will stick with it, though. – peterp Feb 04 '13 at 16:24