Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference a page with parameters Wicket

I need to send Wicket links (through mail, for example) which references instances in the system.

For example, the mail could contain:

From: ...@... To: ...@... Subject: Order Pending

... txt... Click here to go: http://I.dont.care.the.style.of.the.linkPage.OrderDetailPage?orderId=1001 ... txt...

I have two constructor of this OrderDetailPage

public class OrderDetailPage extends BasePage {

public OrderDetailPage(PageParameters parameters){
    this(OrderRepository.getById(parameters.getAsInteger("orderId")), null);
}


public OrderDetailPage(Order order, WebPage back) {
       super(new CompoundPropertyModel<Order>(order));
       //Renders the page for the order received.
       //back is the page we came from. Null hides link.

       ...
    }
...
}

I don't know how to send the links, because, I can't create a Bookmarkable Link because it looks for the default constructor... and of course, I don't have one.

What I'm doing for another page is:

final PageParameters pars = new PageParameters();
pars.add("orderId", "1001");

BookmarkablePageLink<Void> link = new BookmarkablePageLink<Void>("alink", OrderDetailPage.class, pars); 
                        
link.add(new Label("id", "1001"));  
add(link);

Markup:

<li><a href="#" wicket:id="alink"><span wicket:id="id"/></a></li>

The generated URL is

http://localhost:8080/wicket/bookmarkable/packagePath.OrderDetailPage?orderId=1001

Which is OK, but Still, doesn't call the "parameters" constructor.

FIX:

I fix this, but I know the solution is NOT OK.

public OrderDetailPage() {
        this(WicketApplication.orderRepository.get(Integer
                .parseInt(RequestCycle.get().getRequest()
                        .getRequestParameters().getParameterValue("orderId").toString())),
                null);

    }

EDIT: I read something about "mounting" the URL, could this work? How?

like image 566
anizzomc Avatar asked Dec 29 '25 06:12

anizzomc


1 Answers

The BookMarkablePageLink has 2 constructors: one for connecting to the default constructor of the linked page, and one with an extra parameter to supply the link with PageParameters, which will call the constructor with the PageParameters.

You create the link like so:

PageParameters pars = new PageParameters();
pars.add("id", 12345);
add(new BookmarkablePageLink("id", MyPage.class, pars);

This also works with the setResponsePage method:

PageParameters pars = new PageParameters();
pars.add("id", 12345);
setResponsePage(MyPage.class, pars);
like image 91
Martijn Dashorst Avatar answered Dec 30 '25 23:12

Martijn Dashorst