I have Wicket app, in WebApplication I do:
public class AppStart extends WebApplication{
public AppStart(){
}
@Override
protected void init(){
super.init();
mountPage("/index.html", StandardPage.class);
mountPage("/another.html", StandardPage.class);
}
}
but when I access /index.html then I'm redirected to /another.html page. Has been thinking that at the moment of creating page StandardPage.class will be instantiated so these two pages will be handled by two separate objects of StandardPage.class?
yes, it is true. Wicket has its own complex mechanism of handling URLs and how to redirect browser to a specific target. In Wicket using two or more different paths to mount the same page class has no idea (by default).
SOLUTION 1
If you really want to get the same functionality on different URLs, use a simple descendant
public class StandardPage2 extends StandardPage {
//... define the same constructors from StandardPage
}
Your code
@Override
protected void init(){
super.init();
mountPage("/index.html", StandardPage.class);
mountPage("/another.html", StandardPage2.class);
}
Do not forget to use correctly
setResposonsePage(StandardPage.class);
or
setResposonsePage(StandardPage2.class);
SOLUTION 2
The following example shows how you can use a page parameter as a part of URL. Let's there are users in a databases and each user has its own page that is accessible on a unique URL. Also each user can do some optional operations and the operation name is ever included in URL and there are some other pages mounted to their own URIs. So URIs should look like
/home
/login
/logout
/martin
/martin/edit
/martin/detail
/petr
/petr/edit
/petr/detail
/
/texts/my-super-article-1
/texts/my-super-article-2
/events/actual
/fotos/from-my-first-holiday
/fotos/from-my-second-holiday
In this case it is possible to use the default MontedMapper, that is ever implemented in Wicket. The mapping is
mountPage("/home", HomePage.class);
mountPage("/login", LoginPage.class);
mountPage("/logout", LogoutPage.class);
mountPage("/${nick}/${action}", UserProfilePage.class);
mountPage("/texts/${page}", TextPages.class);
mountPage("/events/${page}", EventPages.class);
mountPage("/fotos/${page}", FotoPages.class);
and you have to implement the UserProfilePage and its constructor with PageParameters
public class UserProfilePage extends WebPage {
public UserProfilePage(PageParameters pageParameters) {
super(pageParameters);
StringValue nick = pageParameters.get("nick");
StringValue action = pageParameters.get("action");
// any code
String nickName = nick.toString();
boolean defaultAction = action.isEmpty(); // default action
}
}
SOLUTION 3
Also you can override IRequestMapper and some other classes, but I think it is too much complicated and it is not necessary in your case.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments