Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the code is called from inside a component (or page):</p> <pre><code>urlFor(new ResourceReference("sharedResourceName")); </code></pre> <p>or</p> <pre><code>RequestCycle.get().urlFor(new ResourceReference("sharedResourceName")); </code></pre> <p>Sample application below. I used a ByteArrayResource for simplicity, but any Resource subclass will do:</p> <p>WicketApplication.java</p> <pre><code>package app1; import org.apache.wicket.protocol.http.WebApplication; import org.apache.wicket.request.target.coding.IndexedParamUrlCodingStrategy; import org.apache.wicket.resource.ByteArrayResource; public class WicketApplication extends WebApplication { @Override protected void init() { super.init(); getSharedResources().add("testResource", new ByteArrayResource("text/plain", "This is a test".getBytes())); mount(new IndexedParamUrlCodingStrategy("home/very/deep/folder", getHomePage())); } public Class&lt;HomePage&gt; getHomePage() { return HomePage.class; } } </code></pre> <p>HomePage.java</p> <pre><code>package app1; import org.apache.wicket.PageParameters; import org.apache.wicket.ResourceReference; import org.apache.wicket.behavior.SimpleAttributeModifier; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.WebPage; public class HomePage extends WebPage { public HomePage(final PageParameters parameters) { CharSequence resourceHref = urlFor(new ResourceReference("testResource")); add(new Label("link", "Click me!") .add(new SimpleAttributeModifier("href", resourceHref))); } } </code></pre> <p>HomePage.html</p> <pre><code>&lt;html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd" &gt; &lt;body&gt; &lt;a wicket:id="link"&gt;&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

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