>urlfor(new ResourceReference(MyComponent.class, "image.png"));
Alright! That works.
And Enrique, now I understand what you were telling me. Thanks.
Igor, I made this little thing:
public class PackageImage extends WebComponent {
private static final long serialVersionUID = 1L;
private Class<?> location;
public PackageImage(String id, Class<?> location) {
super(id);
this.location = location;
}
@Override protected void onComponentTag(final ComponentTag tag) {
checkComponentTag(tag, "img");
super.onComponentTag(tag);
tag.put("src", urlFor(new ResourceReference(location, tag.getString
("src").toString())));
}
}
So that I can have in MyComponent.html:
<img wicket:id="img" src="open.png"/> <-- just the image file
name -->
and in MyComponent.java:
add(new PackageImage("img", MyComponent.class));
And this gets the src fixed up to point to the image file. I think it could
be useful in general. Should Wicket have one built-in?
On Sun, Mar 30, 2008 at 9:33 PM, Igor Vaynberg <[EMAIL PROTECTED]>
wrote:
> urlfor(new ResourceReference(MyComponent.class, "image.png"));
>
> -igor
>
>
> On Sun, Mar 30, 2008 at 9:28 PM, Matthew Young <[EMAIL PROTECTED]> wrote:
> > >wicket:link doesnt touch components afaik
> >
> > :((((( I need it to be a component. My code is basically this:
> >
> > add(new WebMarkupContainer("img"));
> >
> > Can I do something like this:
> >
> > add(new WebMarkupContainer("img") {
> >
> > @Override protected void onComponentTag(final ComponentTag tag)
> > {
> > super.onComponentTag(tag);
> > tag.put("src", GIVE-ME-YOU-LOCATION-PLEASE + tag.getString
> ("src"));
> > }
> >
> > });
> >
> > where "GIVE-ME-YOU-LOCATION-PLEASE" is some method to get
> > "/resources/com.mycompany.component.MyComponent/"?
> >
> > On Sun, Mar 30, 2008 at 9:05 PM, Igor Vaynberg <[EMAIL PROTECTED]
> >
> >
> >
> > wrote:
> >
> > > thats because you have a wicket:id there. wicket:link doesnt touch
> > > components afaik
> > >
> > > -igor
> > >
> > >
> > > On Sun, Mar 30, 2008 at 8:57 PM, Matthew Young <[EMAIL PROTECTED]>
> wrote:
> > > > So I did this:
> > > >
> > > >
> > > > <html xmlns:wicket>
> > > > <body>
> > > > <wicket:panel>
> > > > <wicket:link><img wicket:id="open" src="open.png
> "/></wicket:link>
> > > > </wicket:panel>
> > > > </body>
> > > > </html>
> > > >
> > > > the src attr doesn't change, it stays as "open.png" and not change
> to
> > > >
> > > > "/resources/com.mycompany.component.MyComponent/open.png"
> > > >
> > > >
> > > >
> > > > On Sun, Mar 30, 2008 at 8:37 PM, <[EMAIL PROTECTED]> wrote:
> > > >
> > > > > Use wicket:link tags around the image
> > > > >
> > > > > -igor
> > > > >
> > > > > On 3/30/08, Enrique Rodriguez <[EMAIL PROTECTED]> wrote:
> > > > > > On Sun, Mar 30, 2008 at 7:45 PM, Matthew Young <
> [EMAIL PROTECTED]>
> > > > > wrote:
> > > > > > > ...
> > > > > > > I don't want to hard code
> > > > > > > "/resources/com.mycompany.component.MyComponent/open.png" in
> the
> > > > > template
> > > > > > > and just have <img src="open.png" .../>. Is there someway to
> work
> > > out
> > > > > > the
> > > > > > > prefix "/resources/com.mycompany.component.MyComponent/" and
> fix
> > > up
> > > > > src
> > > > > > > attribute in code?
> > > > > >
> > > > > > If you are in a Component you can call Component#urlFor().
> > > > > >
> > > > > > If not in a Component, you can call:
> > > > > >
> > > > > > RequestCycle.get()#urlFor();
> > > > > >
> > > > > > You can use the form that takes a ResourceReference for the
> image.
> > > > > >
> > > > > > HTH,
> > > > > >
> > > > > > Enrique
> > > > > >
> > > > > >
> > > ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > > >
> > > > > >
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > >
> > > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>