Wicket IndexedParamUrlCodingStrategy:如何指定缺失的参数?

发布于 2024-11-07 10:17:19 字数 1194 浏览 0 评论 0原文

如何为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

把人绕傻吧 2024-11-14 10:17:19

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)

89    if (!url.endsWith("/"))
90    {
91        url.append("/");
92    }

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文