Wicket 1.5 PageParameters are empty

1.1k Views Asked by At

I'm a fairly experienced Wicket user but I'm making my first foray into 1.5 and the mountPage() syntax is defeating me.

I'm clearly doing something wrong because I can't fine a single reference of someone having this same issue. So here it goes:

This is what I have in my init() method:

@Override
public void init()
{
    super.init();

    System.out.println("mounting: /requirement/${id}");

    mountPage("/requirement/${id}", RequirementPage.class);
}

I've verified this is working by changing the "requirement" part to other things and back. This is the (only) constructor for RequirementPage:

public RequirementPage()
{
    try
    {
        PageParameters params = getPageParameters();

        System.out.println("named keys: " + params.getNamedKeys());
        System.out.println("index keys: " + params.getIndexedCount());

        StringValue value = params.get("id");

        System.out.println("requirement: " + value);

In my server console (Jetty8) I see this on startup:

mounting: /requirement/${id}

And when I make a request to /requirement/0 I see this:

named keys: []
index keys: 0
requirement: null

I've looked at a number of things and I can't see anything different about what I am doing from what the wiki, or other examples show.

Any help is appreciated.

thanks,

-James

2

There are 2 best solutions below

2
On BEST ANSWER

You need to provide Wicket a constructor with PageParameters, otherwise there's no possibility for wicket to wrap those parameters and provide it to your page.

Apart from that, you can access requestparameters via getRequestCycle().getRequest().getRequestParameters() without having a constructor with pageparameters, but as far as youd like wicket to manage and mount your pages and parameters and having them bookmarkable, it is necessary to provide a default constructor, with or without pageparameters, occording to your requirement of recieving parameters or not.

0
On

You can try this;

@Override
public void init()
{
    super.init();

    mountPage("requirement", RequirementPage.class);
}

Then call the url like this "http://localhost:8080/requrement?id=111" And then you can get id with your constructor. But you can use your web page constructor like this;

public RequirementPage(PageParameters parameters)
{
 ...
}