You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Martin Grigorov (JIRA)" <ji...@apache.org> on 2013/02/04 10:58:12 UTC

[jira] [Commented] (WICKET-5004) Add light-weight possibility to generate URLs from Page and PageParameters without having the WebApplication actually running.

    [ https://issues.apache.org/jira/browse/WICKET-5004?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13570093#comment-13570093 ] 

Martin Grigorov commented on WICKET-5004:
-----------------------------------------

I'm not sure how this is possible in Wicket 1.3/1.4.

The ServletContext is needed and the filter path where WicketFilter listens to be able to calculate the relative urls.
If you need full url (like http://host/...) then you can use a helper class that uses bi directional map (String -> Class<Page>). In Wicket code you just need to do somthing like: 

void Helper.mount(webApp) {
  for (entry : map) {
    webApp.mountPage(entry.key, entry.value)
  }
}

In your non-Wicket code: 
  prefix + map.getKey(pageClass)
where prefix is the part that Wicket needs usually to calculate the urls: http://host/contextPath/filterPath.
                
> Add light-weight possibility to generate URLs from Page and PageParameters without having the WebApplication actually running.
> ------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-5004
>                 URL: https://issues.apache.org/jira/browse/WICKET-5004
>             Project: Wicket
>          Issue Type: Improvement
>          Components: wicket
>    Affects Versions: 6.5.0
>            Reporter: Peter Parson
>
> In certain scenarios it is useful to be able to generate wicket URLs without having the wicket application running, i.e. a mail notification system running which needs to include dynamic URLs in the mails, or an XML sitemap generator running on a different server.
> With Wicket 1.3.x, this was an easy task: we just needed to (statically) provide the UrlRequestCodingStrategy, the PageClass and PageParameters and any other module depending on our wicket module could obtain the URLs.
> With Wicket 6.x it's not so easy, it seems to be impossible without having the application actually running. I have found the solution I have described here: http://stackoverflow.com/questions/13015743/how-to-obtain-wicket-url-from-pageclass-and-pageparameters-without-running-wicke
> But this seems to be a little hacky, and causes problems if executed multiple times (since the WebApplication is somewhere registered within the context, but cannot be destroyed)
> A code example from our old (1.3.x) solution, to give you an idea of what we did.
> We had a spring bean in our Wicket module which offered methods like this:
> public String getUrlFor(MyDomainObject o) {
> 	Class pClass = MyDomainObjectTargetPage.class;
> 	PageParameters pp = MyDomainObjectTargetPage.pageParametersFor(o);
> 	IRequestTargetUrlCodingStrategy urlCodingStragy = MyDomainObjectTargetPage.URL_CODING_STRATEGY;
> 	BookmarkablePageRequestTarget target = new BookmarkablePageRequestTarget(pClass, pp);
> 	return "/" + urlCodingStragy.encode(target).toString()
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira