[英]Wicket human-readable URLs
Started learning Wicket after ASP.NET MVC and feel a little bit confused about managing its URLs.在 ASP.NET MVC 之后开始学习 Wicket,对管理其 URL 感到有点困惑。 Here's the code:
这是代码:
Application :应用:
package com.test.wicketapp1;
import org.apache.wicket.protocol.http.WebApplication;
public class WicketApplication extends WebApplication {
public WicketApplication() {
mountPage("/page1", HomePage.class);
mountPage("/page2", Page2.class);
}
@Override public Class<HomePage> getHomePage() {
return HomePage.class;
}
}
HomePage :主页:
package com.test.wicketapp1;
import java.io.IOException;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.WebPage;
public class HomePage extends WebPage {
private static final long serialVersionUID = 1L;
public HomePage(final PageParameters parameters) throws IOException {
BookmarkablePageLink<Page2> bookmarkablePageLink = new BookmarkablePageLink<Page2>("gopage2link", Page2.class);
add(bookmarkablePageLink);
}
}
HomePage markup :主页标记:
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<title>Apache Wicket Quickstart</title>
</head>
<body>
<a href="#" wicket:id="gopage2link">go page 2</a>
</body>
</html>
What I wanted to have is pretty simple.我想要的很简单。 I expected that there would be 2 urls: "/page1" for HomePage.class and "/page2" for Page2.class, then my HomePage has a link that navigates to Page2 and when HomePage is rendered, that link should have an URL of "/page2".
我预计会有 2 个网址:HomePage.class 的“/page1”和 Page2.class 的“/page2”,然后我的主页有一个导航到 Page2 的链接,当主页呈现时,该链接应该有一个 URL “/第2页”。
When I run the application and go to home page, it is rendered like this:当我运行应用程序和 go 到主页时,它呈现如下:
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<title>Apache Wicket Quickstart</title>
</head>
<body>
<a href="./wicket/bookmarkable/com.test.wicketapp1.Page2" wicket:id="gopage2link">go page 2</a>
</body>
</html>
I expected to have something like:我希望有类似的东西:
<a href="/page2" wicket:id="gopage2link">go page 2</a>
instead.反而。 What did I miss?
我错过了什么?
The problem is - I should use app's init
method instead of ctor to define the mappings.问题是——我应该使用应用程序的
init
方法而不是 ctor 来定义映射。
have a look at this.看看这个。 It might help
可能有帮助
https://cwiki.apache.org/WICKET/request-mapping.html https://cwiki.apache.org/WICKET/request-mapping.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.