It's me again. When I started using Wicket around version 1.1, I needed
complete control over the URLs so that all of the URLs on the public portion
of the site were bookmarkable, and SEO friendly. Somewhere I read that you
do this by either using all bookmarkable pages, or by implementing your own
IRequestTargetUrlCodingStrategy. I chose the latter to get all of the
parameter encoding / decoding out of the WebPage(PageParameters)
constructors. This kept all of the logic regarding encoding and decoding
URLs in their own objects - and I was able to use some good extensible
strategies to use throughout the entire site.
Now, though, I am having a problem with sessions, and I'm realizing that all
of the links throughout my page, even though they end up being encoded to a
bookmarkable URL (therefore - don't need to be stateful) are all appearing
as stateful, and cause a session to be bound on bookmarkable / otherwise
stateless pages.
Basically what I have now is something like what I've pasted below. It
works great, but the problem I have is that if in my link I override
getStatelessHint() and return false, the session is no longer created, but
my url strategy doesn't work anymore either because the IRequestTarget
passed to my URL strategy is BookmarkablePageRequestTarget, and I can't
access my link with that to get the necessary information.
I need the correct way of implementing my URL control. Any ideas?
public class ViewPostLink extends Link {
private static final Logger LOGGER =
Logger.getLogger(ViewPostLink.class);
public ViewPostLink(String id, IModel model) {
super(id, model);
}
@Override
public void onClick() {
LOGGER.warn("USING ONCLICK METHOD OF ViewPostLink LINK - SHOULD BE
USING URL STRATEGY");
}
public IPostSummary getPost() {
return (IPostSummary) getModelObject();
}
}
Then I have a custom url strategy, with code like below. I mount one of
these per post category, with a different mount point.
public class ViewPostStrategy {
.. some code omitted for brevity
public boolean matches(IRequestTarget rt) {
boolean matches = true;
matches = matches && rt instanceof ListenerInterfaceRequestTarget;
matches = matches && ((ListenerInterfaceRequestTarget)
rt).getTarget() instanceof ViewPostLink;
if (!matches) {
return false;
}
IPostSummary post = ((ViewPostLink)
((ListenerInterfaceRequestTarget) rt).getTarget()).getPost();
matches = matches && post != null;
if (!matches) {
return false;
}
matches = matches &&
(mMountedPostCategory.equals(post.getPostCategory());
return matches;
}
}