如何创建隐藏其参数的 Wicket URL?
我目前正在创建一组带有如下代码的链接:
BookmarkablePageLink<CheeseMain> havarti =
new BookmarkablePageLink<CheeseMain>("havarti", CheeseMain.class);
havarti.setParameter("Title", "Havarti");
havarti.setParameter("Group", "cheeseName");
add(havarti);
出现的 URL 具有以下格式 https://mysite.com/;jsessionid=B85EE5CB0349CCA2FE37AF76AB5C30C1?wicket:bookmarkablePage=:com.mycompany.cheese.CheeseMain&Title=Havarti&group=cheeseName
。
我的问题是我不再希望该链接的 URL 可添加书签。理想情况下,我希望它是像 https://mysite.com/cheese
这样简单的东西,但我可以接受丑陋的 URL。重要的是参数是不可见的。
我应该如何更改生成链接的方式?我研究了 Wicket 提供的不同 URL 编码策略,但没有一个删除参数;他们只是以不同的方式展示它们。
I'm currently creating a set of links with code like this:
BookmarkablePageLink<CheeseMain> havarti =
new BookmarkablePageLink<CheeseMain>("havarti", CheeseMain.class);
havarti.setParameter("Title", "Havarti");
havarti.setParameter("Group", "cheeseName");
add(havarti);
The URL that comes out has the formathttps://mysite.com/;jsessionid=B85EE5CB0349CCA2FE37AF76AB5C30C1?wicket:bookmarkablePage=:com.mycompany.cheese.CheeseMain&Title=Havarti&group=cheeseName
.
My problem is that I no longer want the URL for this link to be bookmarkable. Ideally, I would like it to be something simple like https://mysite.com/cheese
, but I can live with an ugly URL. The important thing is that the parameters aren't visible.
How should I change the way I'm generating my links? I've looked at the different URL encoding strategies that Wicket provides, but none of them remove the parameters; they just display them differently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当页面可添加书签或特定链接可添加书签时,参数才会出现在 URL 中。
如果您创建一个使用
setResponsePage(Page)
(传递 Page 实例)而不是setResponsePage(Class, PageParameters) 导航到页面的
Link
< /code> (传递 Page 类),创建的链接不会指向页面的可添加书签的版本,而是指向有状态的实例。不过,要实现此功能,您不得调用
super(PageParameters)
构造函数(这样 Page 就没有足够的信息来构建无状态 URL)。在此示例中,您可以通过两个不同的链接导航到
SecretPage
,一个是无状态的、可添加书签的,另一个是有状态的。SecretPage
也有两个构造函数。接收一个PageParameters
并调用super
传递它。另一个直接通过构造函数参数接收值,并且不将其传递给super
(如果它调用super(new PageParameters().add("message",message)< 注释行中所示,它会自动重定向到可添加书签的
URL
/
)
code>,如
。
http://host/app/secret
,您必须安装它。您可以在您的WebApplication
类中执行此操作。此示例
使用 Wicket 1.5(仍为 RC4)。 2),并且需要一些修改才能与 1.4.x 一起使用(某些方法和类被重命名,或移动到不同的包),但想法是相同的。
The parameters appear in the URL only if the page is bookmarkable, or the specific link is bookmarkable.
If you create a
Link
that navigates to the page usingsetResponsePage(Page)
(passing a Page instance) instead ofsetResponsePage(Class<Page>, PageParameters)
(passing a Page class), the link created will not point to the bookmarkable version of the page, but to a stateful instance.To make this work, though, you must not call the
super(PageParameters)
constructor (so that the Page doesn't have enough information to build the stateless URL).In this example, you can navigate to the
SecretPage
through two different links, one stateless, bookmarkable, and the other stateful.SecretPage
also has two constructors. One receives aPageParameters
and callssuper
passing it. The other receives the value directly via construcor parameter, and doesn't pass it tosuper
(if it'd calledsuper(new PageParameters().add("message",message)
, as in the commented line, it would automatically redirect to a bookmarkable URL).HomePage.java:
HomePage.html:
SecretPage.java
SecretPage.html
And, to have a simple URL, like
http://host/app/secret
, you must mount it. You can do it in yourWebApplication
class.WicketApplication.java
This example uses Wicket 1.5 (still RC4.2), and need some modifications to work with 1.4.x (some methods and classes were renamed, or moved to different packages), but the idea is the same.
您仍然可以使用您选择的 URL 编码策略并将参数封装到继承的类中,例如:
然后您可以使用:
new BookmarkablePageLink("havarti", Havarti.class)
。You could still use your URL encoding strategy of choice and encapsulate your parameters into an inherited class such as:
Then you can use:
new BookmarkablePageLink<Void>("havarti", Havarti.class)
.