On Wed, Oct 21, 2009 at 07:57:12PM +0200, Ceki Gulcu wrote: > Hello, > > I am trying to defined shared images in a Wicket application. > > In my prokect, the image file "help.gif" is located under the > src/main/java/com/foo/ folder of my project. I have created an empty > class called Images. > > package com.foo; > public class Images { > } > > In the init() method of my web-application, I add help.gif as a shared > resource: > > public class MyApplication extends WebApplication { > > > @Override > protected void init() { > ... > PackageResource pr = PackageResource.get(Images.class, "help.gif"); > sharedResources.add("help.gif", pr); > } > } >
I normally don't need to do anything in my app's init() method for images. > In markup, I attempt to access the images as > > <wicket:link> > <td><img src="/resources/help.gif" align="top"/></td> > </wicket:link> > You would use <wicket:link> when the image is in the same package as the markup. In this case, you would just put in <img src="help.gif"> and Wicket will re-write the src attribute to the right value. This works well if you like to preview your markup in a browser. Since your images are (I think) in a different package, you should get rid of the <wicket:link> tag. (Actually, I think using a relative path to the right package in src might work with <wicket:link>, but I never do it that way. See below.) > Unfortunately, this does not seem to work. However, the following > markup works just fine but it's too cumbersome to write. > > <wicket:link> > <img src="resources/org.apache.wicket.Application/help.gif"/> > </wicket:link> > > Reading page 229 of the Wicket in Action book, I would have thought > that the "/resources/help.gif" reference would have worked. Quoting > from the book: > > The resource is then available through a stable URL (/resources/discounts), > independent of components. (page 229) > > What is the idiomatic way in Wicket to reference shared images? > Here's my idiom. First, in the same package as my images, I create a class that extends ResourceReference: public class MyImage extends ResourceReference { public MyImage(String name) { super(MyImage.class, name); } } Then, I attach an Image component to the <img> tag: <img wicket:id="smiley"/> add(new Image("smiley", new MyImage("smiley.gif"))); No code needed in Application.init(), and no <wicket:link> tags required. jk > Many thanks in advance for your response, > > -- > Ceki Gülcü > Logback: The reliable, generic, fast and flexible logging framework for Java. > http://logback.qos.ch > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org