You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by wfaler <wi...@gmail.com> on 2007/09/25 15:24:47 UTC
Using Resource to provide background attribute to td-tag?
Hi,
I want to use a ResourceReference (or something comparable) to set the
background-attribute of a td-cell with an image on my classpath.
How do I achieve this?
It is quite straightforward for images, but it gets trickier with
background-images to other html elements..
/ Wille
--
View this message in context: http://www.nabble.com/Using-Resource-to-provide-background-attribute-to-td-tag--tf4515517.html#a12879415
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Using Resource to provide background attribute to td-tag?
Posted by Gerolf Seitz <ge...@gmail.com>.
hi,
i'd say either:
myTd.add(new AttributeModifier("style", true, "background-image:url(" +
RequestCycle.urlFor(myImage) + ");"));
// use an AttributeAppender if you want to preserve an existing style
attribute
or override onComponentTag of myTd and put it in the tag like:
tag.put("style", "background-image:url(" + RequestCycle.urlFor(myImage) +
");");
there maybe even other ways though (like interpolating a css file with the
url and rendering it in the head)
hth,
gerolf
On 9/25/07, wfaler <wi...@gmail.com> wrote:
>
>
> Hi,
> I want to use a ResourceReference (or something comparable) to set the
> background-attribute of a td-cell with an image on my classpath.
> How do I achieve this?
> It is quite straightforward for images, but it gets trickier with
> background-images to other html elements..
>
> / Wille
> --
> View this message in context:
> http://www.nabble.com/Using-Resource-to-provide-background-attribute-to-td-tag--tf4515517.html#a12879415
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Using Resource to provide background attribute to td-tag?
Posted by Al Maw <wi...@almaw.com>.
wfaler wrote:
> Actually, I removed all the "background" attributes and added them as
> "background:url(mygif.gif);" in the stylesheet, that I add to the header
> with:
> add(HeaderContributor.forCss(FrameworkStaticResource.class, "style.css"));
>
> If I am not mistaken, this should pick the background images up from the
> same package/directory as the stylesheet, right?
Yep. If you want package resources, that will automagically Just
Work(tm). Sorry - was assuming you wanted some other kind of resource,
in which case, my previous post was the way to achieve that.
But yes, in your case, keep it simple. ;-)
Regards,
Al
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Using Resource to provide background attribute to td-tag?
Posted by wfaler <wi...@gmail.com>.
Actually, I removed all the "background" attributes and added them as
"background:url(mygif.gif);" in the stylesheet, that I add to the header
with:
add(HeaderContributor.forCss(FrameworkStaticResource.class, "style.css"));
If I am not mistaken, this should pick the background images up from the
same package/directory as the stylesheet, right?
Al Maw wrote:
>
> wfaler wrote:
>> Hi,
>> I want to use a ResourceReference (or something comparable) to set the
>> background-attribute of a td-cell with an image on my classpath.
>> How do I achieve this?
>> It is quite straightforward for images, but it gets trickier with
>> background-images to other html elements..
>
> If you object to style attributes on your HTML tags, then you can do
> this by writing stuff out to the <head> of your page.
>
> private static final ResourceReference IMAGE = /* ... */;
> ...
> final Component component = /* ... */;
> page.add(new AbstractBehavior() {
> public void renderHead(IHeaderResponse response) {
> String url = urlFor(IMAGE);
>
> String foo = "<style>\n";
> foo += "#" + component.getMarkupId() + " {\n";
> foo += "background-image: url(" + url ")\n;";
> foo += "}\n";
> foo += </style>";
> response.renderString(foo);
> }
> });
>
> Should work. ;-)
>
> Regards,
>
> Al
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Using-Resource-to-provide-background-attribute-to-td-tag--tf4515517.html#a12882758
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Using Resource to provide background attribute to td-tag?
Posted by Al Maw <wi...@almaw.com>.
wfaler wrote:
> Hi,
> I want to use a ResourceReference (or something comparable) to set the
> background-attribute of a td-cell with an image on my classpath.
> How do I achieve this?
> It is quite straightforward for images, but it gets trickier with
> background-images to other html elements..
If you object to style attributes on your HTML tags, then you can do
this by writing stuff out to the <head> of your page.
private static final ResourceReference IMAGE = /* ... */;
...
final Component component = /* ... */;
page.add(new AbstractBehavior() {
public void renderHead(IHeaderResponse response) {
String url = urlFor(IMAGE);
String foo = "<style>\n";
foo += "#" + component.getMarkupId() + " {\n";
foo += "background-image: url(" + url ")\n;";
foo += "}\n";
foo += </style>";
response.renderString(foo);
}
});
Should work. ;-)
Regards,
Al
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Using Resource to provide background attribute to td-tag?
Posted by Gerolf Seitz <ge...@gmail.com>.
On 9/25/07, wfaler <wi...@gmail.com> wrote:
>
> I want to use a ResourceReference (or something comparable)
apparently, the words in parenthesis are sometimes more important than the
rest, so yes: keep it simple...
gerolf