RobAu RobAu - 14 days ago 5
Ajax Question

Wicket and Wicket-select2 both use PageParameter 'q'. How to solve?

I have a set of

PageParameter
s for my page, one is
q
(for query). This allows for nice URLs like:

http://myapplication/search?q=myquery.

But when I have a
wicket-select2
component on my page, it initializes the query for the select2 with the same value of the
PageParameter
q
.

This causes the select2 to return an empty list of options, while the user has not even select anything yet.

I know I can change the name of my PageParameters (unfortunately, some clients will have to change urls). Or I can override the methods in
select2
that use the
q
parameters.

I wondered if there is a better solution?

[Update]
I also posted this question on the Wicket mailinglist, and was asked to create an issue: https://github.com/wicketstuff/core/issues/563

Will post the answer when thats done :)

Answer

As pointed in this [1] answer you can use stateless mounting for this

In most recent 7.x version (not merged to master yet) you can use following code to change mapping

Select2MultiChoice<CategoryTranslation> c = new Select2MultiChoice<CategoryTranslation>("categories");
c.getSettings().setQueryParam("qq");

This most probably will be the final solution :)

[1] http://markmail.org/message/ox7rmtzqwfqt5np5