Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the URL to a Wicket shared resource?
    primarykey
    data
    text
    <p>The web designer has given me HTML which looks like:</p> <pre><code>&lt;div .... style="background: transparent url(xxx.png) 170px center no-repeat"&gt; </code></pre> <p>Unfortunately the contents of the image <code>xxx.png</code> is generated by the software, so I have made it a <code>WebResource</code> and use the following strategy to generate the URL for the resource which I then embed in the <code>style=</code> attribute using a Wicket <code>AttributeModifier</code>.</p> <pre><code>// App initialization code String resourceName = ....; getSharedResources().add(resourceName, myWebResource); // Creating the widget String url = getServletContext().getContextPath() + "/resources/org.apache.wicket.Application/" + resourceName ; String style = "background: transparent url(" + url + ") 170px center no-repeat"; div.add(new AttributeModifier("style", new Model&lt;String&gt;(style))); </code></pre> <p>This works fine when I test it locally using Eclipse, but :</p> <ul> <li>When I install this in production, I want to have Apache as a proxy to Jetty such that the context root isn't visible, i.e. Apache forwards a request of <code>/foo</code> onto Jetty as <code>/context-root/foo</code>.</li> <li>In general, I don't think this is very elegant. I'm sure I am duplicating Wicket code here?</li> </ul> <p>I understand Wicket solves this problem of context-roots and Apache proxying by only using relative URLs. That would be the most elegant solution I suspect. But if I have e.g. a <code>IndexedParamUrlCodingStrategy</code> then the URL could be of arbitrary length and I don't know how many <code>..</code> to include to get back to <code>/resources</code>.</p> <p><strong>Edit</strong>: The current solution is to use absolute URLs as in my code example above, and in Apache (a) rewrite <code>/context-root/*</code> into <code>/*</code> (b) as before then ADD the context root to all requests (c) forward to Jetty. That way most URLs can be without the context root but some URLs (to my resources) can have the context root and it's OK. But I don't like this solution!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload