Java – how to reference a wicket page with parameters
I need to send wicket links (e.g. by email) to reference instances in the system
For example, a message might contain:
From:... @... To:... @... Subject: order pending
... text... Click here: http://I.dont.care.the.style.of.the.linkPage.OrderDetailPage?orderId=1001 ... text
I have two constructors for 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 a link because I can't create a bookmarkable link because it looks for the default constructor... Of course, I don't
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);
Marking:
<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
Yes, but the parameter constructor will still not be called
Fixed:
I solved the problem, but I know the solution won't work
public OrderDetailPage() {
this(WicketApplication.orderRepository.get(Integer
.parseInt(RequestCycle.get().getRequest()
.getRequestParameters().getParameterValue("orderId").toString())),null);
}
Editor: I read something about "Mount" website. Is this feasible? What about?
Solution
Bookmarkablepagelink has two constructors: one is the default constructor for connecting to the linked page, and the other takes additional parameters to provide a link with pageparameters, which will call the constructor with pageparameters
You can create links like this:
PageParameters pars = new PageParameters();
pars.add("id",12345);
add(new BookmarkablePageLink("id",MyPage.class,pars);
This also applies to the setresponsepage method:
PageParameters pars = new PageParameters();
pars.add("id",12345);
setResponsePage(MyPage.class,pars);
