Thursday, May 07, 2009

Wicket, Form and GET method

If you are using Wicket and has previous web development experience, one of the good things is that, everytime you submit, Wicket takes care of everything. However, URL after form submission is something strange as it leads you to wicket URLs that is depending on the user's session. The question is: how do you make Wicket behave as a plain form that submits using GET method?

First, I set my URL strategy to make it bookmarkable:

MixedParamUrlCodingStrategy mypageURL = new MixedParamUrlCodingStrategy(
new String[]{"type"}

Then, in the page code, I override the form onSubmit() method to do the following:

form.add(new SubmitLink("update") {
public void onSubmit() {
PageParameters parameters = new PageParameters();
parameters.add("period", Integer.toString(getPeriod()));
parameters.add("unit", getUnit().toString());
parameters.add("type", getType());
setResponsePage(getPage().getClass(), parameters);

So, after the user click on the submit link, it submits it similarly to a GET method and I get a nice URL like:


The result is that this makes URLs much more bookmarkable throughout the session.
Post a Comment