Wicket IndexedParamUrlCodingStrategy:如何指定缺失的参数?
如何为 IndexedParamUrlCodingStrategy 指定空位置参数?
我有一个 SearchPage
安装:
mount(new IndexedParamUrlCodingStrategy("search", SearchPage.class));
这允许我构建如下网址:
/search/category/searchTerm/all/21-30
我可以成功检索位置参数:
String category = parameters.getString("0", "");
String searchTerm = parameters.getString("1", "");
String filter = parameters.getString("2", "all");
String pagination = parameters.getString("3", "1-10");
这允许带有空参数的网址,例如:
/search//searchTerm/all/21-30 /* no category specified */
这工作正常,但我可以'似乎没有创建指向 SearchPage
的链接,但缺少参数。
params.put("0", ""); // try to set "empty" category
params.put("1", "searchTerm");
params.put("2", "all");
params.put("3", "21-30");
BookmarkablePageLink<SearchPage> link = new BookmarkablePageLink<SearchPage>("link", SearchPage.class, linkParams);
这会产生一个带有如下 URL 的链接:
/search/searchTerm/all/21-30
而不是我想要的:
/search//searchTerm/all/21-30
How can I specify empty positional params for IndexedParamUrlCodingStrategy?
I have a SearchPage
mounted with:
mount(new IndexedParamUrlCodingStrategy("search", SearchPage.class));
This allows me to build urls like:
/search/category/searchTerm/all/21-30
I can successfully retrieve the positional params with:
String category = parameters.getString("0", "");
String searchTerm = parameters.getString("1", "");
String filter = parameters.getString("2", "all");
String pagination = parameters.getString("3", "1-10");
This allows for URLs with empty params, such as:
/search//searchTerm/all/21-30 /* no category specified */
This works fine, but I can't seem to create links to the SearchPage
with missing params.
params.put("0", ""); // try to set "empty" category
params.put("1", "searchTerm");
params.put("2", "all");
params.put("3", "21-30");
BookmarkablePageLink<SearchPage> link = new BookmarkablePageLink<SearchPage>("link", SearchPage.class, linkParams);
This results in a link with URLs like:
/search/searchTerm/all/21-30
rather than my intended:
/search//searchTerm/all/21-30
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道 IndexedParamUrlCodingStrategy 是否可以实现这一点。您可能必须切换到 MixedParamUrlCodingStrategy< /a> 通过一组定义的参数创建 URL,而不是“从 0 开始按升序排列的数字参数”。 IndexedParamUrlCodingStrategy 的 Javadoc 的这一部分让我认为它要么不适合您的用例,要么您必须“发明”一些神奇的非空空字符串(它的味道真的很糟糕)。
IndexedParamUrlCodingStrategy 不会产生任何“//”(刚刚检查了来源)
显然您可以使其适合您的用例或将其报告为错误,但我不知道这是否不是一个功能...
I don't know if this is possible with an IndexedParamUrlCodingStrategy. You might have to switch to an MixedParamUrlCodingStrategy that creates the URL by a defined set of parameters instead of "numeric parameters in ascending order starting with 0". This part of the Javadoc of the IndexedParamUrlCodingStrategy makes me think that either it's not suited for your usecase or you have to 'invent' some magic non-empty-empty String (which just smells real bad).
The IndexedParamUrlCodingStrategy wouldn't produce any "//" (just checked the sources)
Obviously you could make it to fit your usecase or report that as a bug, but I don't know if this isn't a feature...