开发者

Wicket IndexedParamUrlCodingStrategy: how to specify missing parameters?

开发者 https://www.devze.com 2023-03-05 19:04 出处:网络
How can I specify empty positional params for IndexedParamUrlCodingStrategy? I have a SearchPage mounted with:

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消