You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by John Meredith <ps...@t-online.de> on 2004/01/27 21:25:21 UTC

Dynamic ContextAsset?

Hi,

I have a component which contains some images based on the context it
finds itself in. In my case, the images change depending on the which
brand a product belongs too, however the images themselves are not
related to the product in question.

As I'd like to be able to define a brand dynamically with it's
associated images, I'm stuck with the resulting image paths (after
upload).

My question is thus: Is it at all possible to create ContextAssets
dynamically and if so how? I'm aware of being able to use the @Any tag
on an <img>, however I'd also like to use the @Rollover in some cases so
an IAsset is required (plus I don;t want to rewrite a new @Rollover).

TIA,

  John

-- 
John Meredith <ps...@t-online.de>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


RE: Dynamic ContextAsset?

Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
Try this ....

private IAsset getImageAsset(String path) 
{
  IRequestCycle cycle = getPage().getRequestCycle();

  ServletContext servletContext =
    cycle.getRequestContext().getServlet().getServletContext();

  Locale locale = getPage().getLocale();

  ContextResourceLocation baseLocation = 
    new ContextResourceLocation(servletContext, path, locale);

  ContextResourceLocation localized = 
    (ContextResourceLocation) baseLocation.getLocalization(locale);
		
  return new ContextAsset(localized, null);
}



--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Tapestry: Java Web Components 
http://howardlewisship.com


> -----Original Message-----
> From: John Meredith [mailto:psynix@t-online.de] 
> Sent: Wednesday, January 28, 2004 2:41 PM
> To: Tapestry users
> Subject: Re: Dynamic ContextAsset?
> 
> 
> Well, I've replaced the ILocation with null. So far so good.
> 
> Now the problem I'm having is with localised images. The resulting
> ContextAsset is reporting (through
> getLocalization(getPage().getLocale())) that the image location is
> correct, however the HTML source shows only the unlocalised 
> image path.
> 
> So, instead of "image_en.gif" I'm getting "image.gif".
> 
> My code is now as follows:
> 
> [snip]
> private IAsset getImageAsset(String path) {
>   IRequestCycle cycle = getPage().getRequestCycle();
>   ServletContext servletContext =
> cycle.getRequestContext().getServlet().getServletContext();
>   ContextResourceLocation resLoc = new
> ContextResourceLocation(servletContext, path, getPage().getLocale());
> 		
>   return new ContextAsset(resLoc, null); // No ILocation necessary
> }
> [/snip]
> 
> Does anyone have any ideas as to why this would be?
> 
> TIA,
> 
>   John
> 
> On Tue, 2004-01-27 at 23:49, John Meredith wrote:
> > [Followup]
> > 
> > By tracing through Tapestry's API docs, I've come up with 
> the following
> > (sorry if the formatting get's garbled by the list):
> > 
> > public IAsset getImageAsset(String path) {
> > 	IRequestCycle cycle = getPage().getRequestCycle();
> > 	ServletContext servletContext =
> > cycle.getRequestContext().getServlet().getServletContext();
> > 	ContextResourceLocation resLoc = new
> > ContextResourceLocation(servletContext, path, 
> getPage().getLocale());
> > 
> > 	AssetSpecification spec = new AssetSpecification();
> > 	spec.setPath(path);
> > 	spec.setType(AssetType.CONTEXT);
> > 
> > 	return new ContextAsset(resLoc, spec.getLocation());
> > }
> > 
> > which actually works.
> > 
> > I have two further questions though:
> > 
> > 1. Why does an asset need 2 an IResourceLocation and an 
> ILocation? I'm
> > obviously missing somehting fundamental here.
> > 2. Does this seem like a reasonable solution?
> > 
> > Best regards,
> > 
> >   John
> > 
> > On Tue, 2004-01-27 at 21:25, John Meredith wrote:
> > > Hi,
> > > 
> > > I have a component which contains some images based on 
> the context it
> > > finds itself in. In my case, the images change depending 
> on the which
> > > brand a product belongs too, however the images themselves are not
> > > related to the product in question.
> > > 
> > > As I'd like to be able to define a brand dynamically with it's
> > > associated images, I'm stuck with the resulting image paths (after
> > > upload).
> > > 
> > > My question is thus: Is it at all possible to create ContextAssets
> > > dynamically and if so how? I'm aware of being able to use 
> the @Any tag
> > > on an <img>, however I'd also like to use the @Rollover 
> in some cases so
> > > an IAsset is required (plus I don;t want to rewrite a new 
> @Rollover).
> > > 
> > > TIA,
> > > 
> > >   John
> -- 
> John Meredith <ps...@t-online.de>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Dynamic ContextAsset?

Posted by John Meredith <ps...@t-online.de>.
Well, I've replaced the ILocation with null. So far so good.

Now the problem I'm having is with localised images. The resulting
ContextAsset is reporting (through
getLocalization(getPage().getLocale())) that the image location is
correct, however the HTML source shows only the unlocalised image path.

So, instead of "image_en.gif" I'm getting "image.gif".

My code is now as follows:

[snip]
private IAsset getImageAsset(String path) {
  IRequestCycle cycle = getPage().getRequestCycle();
  ServletContext servletContext =
cycle.getRequestContext().getServlet().getServletContext();
  ContextResourceLocation resLoc = new
ContextResourceLocation(servletContext, path, getPage().getLocale());
		
  return new ContextAsset(resLoc, null); // No ILocation necessary
}
[/snip]

Does anyone have any ideas as to why this would be?

TIA,

  John

On Tue, 2004-01-27 at 23:49, John Meredith wrote:
> [Followup]
> 
> By tracing through Tapestry's API docs, I've come up with the following
> (sorry if the formatting get's garbled by the list):
> 
> public IAsset getImageAsset(String path) {
> 	IRequestCycle cycle = getPage().getRequestCycle();
> 	ServletContext servletContext =
> cycle.getRequestContext().getServlet().getServletContext();
> 	ContextResourceLocation resLoc = new
> ContextResourceLocation(servletContext, path, getPage().getLocale());
> 
> 	AssetSpecification spec = new AssetSpecification();
> 	spec.setPath(path);
> 	spec.setType(AssetType.CONTEXT);
> 
> 	return new ContextAsset(resLoc, spec.getLocation());
> }
> 
> which actually works.
> 
> I have two further questions though:
> 
> 1. Why does an asset need 2 an IResourceLocation and an ILocation? I'm
> obviously missing somehting fundamental here.
> 2. Does this seem like a reasonable solution?
> 
> Best regards,
> 
>   John
> 
> On Tue, 2004-01-27 at 21:25, John Meredith wrote:
> > Hi,
> > 
> > I have a component which contains some images based on the context it
> > finds itself in. In my case, the images change depending on the which
> > brand a product belongs too, however the images themselves are not
> > related to the product in question.
> > 
> > As I'd like to be able to define a brand dynamically with it's
> > associated images, I'm stuck with the resulting image paths (after
> > upload).
> > 
> > My question is thus: Is it at all possible to create ContextAssets
> > dynamically and if so how? I'm aware of being able to use the @Any tag
> > on an <img>, however I'd also like to use the @Rollover in some cases so
> > an IAsset is required (plus I don;t want to rewrite a new @Rollover).
> > 
> > TIA,
> > 
> >   John
-- 
John Meredith <ps...@t-online.de>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Dynamic ContextAsset?

Posted by John Meredith <ps...@t-online.de>.
Ah, that would explain the methods in ILocation.

Thanks for the info.

  - John

On Wed, 2004-01-28 at 01:16, Erik Hatcher wrote:
> On Jan 27, 2004, at 5:49 PM, John Meredith wrote:
> > 1. Why does an asset need 2 an IResourceLocation and an ILocation? I'm
> > obviously missing somehting fundamental here.
> 
> I'm pretty sure the ILocation is there for error reporting and that you 
> would be fine passing in a dummy one (or maybe even null?).
> 
> 	Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
-- 
John Meredith <ps...@t-online.de>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Dynamic ContextAsset?

Posted by Geoff Longman <gl...@intelligentworks.com>.
Null is fine, do it all the time.

Geoff
----- Original Message ----- 
From: "Erik Hatcher" <er...@ehatchersolutions.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Tuesday, January 27, 2004 7:16 PM
Subject: Re: Dynamic ContextAsset?


> On Jan 27, 2004, at 5:49 PM, John Meredith wrote:
> > 1. Why does an asset need 2 an IResourceLocation and an ILocation? I'm
> > obviously missing somehting fundamental here.
> 
> I'm pretty sure the ILocation is there for error reporting and that you 
> would be fine passing in a dummy one (or maybe even null?).
> 
> Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Dynamic ContextAsset?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 27, 2004, at 5:49 PM, John Meredith wrote:
> 1. Why does an asset need 2 an IResourceLocation and an ILocation? I'm
> obviously missing somehting fundamental here.

I'm pretty sure the ILocation is there for error reporting and that you 
would be fine passing in a dummy one (or maybe even null?).

	Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Dynamic ContextAsset?

Posted by John Meredith <ps...@t-online.de>.
[Followup]

By tracing through Tapestry's API docs, I've come up with the following
(sorry if the formatting get's garbled by the list):

public IAsset getImageAsset(String path) {
	IRequestCycle cycle = getPage().getRequestCycle();
	ServletContext servletContext =
cycle.getRequestContext().getServlet().getServletContext();
	ContextResourceLocation resLoc = new
ContextResourceLocation(servletContext, path, getPage().getLocale());

	AssetSpecification spec = new AssetSpecification();
	spec.setPath(path);
	spec.setType(AssetType.CONTEXT);

	return new ContextAsset(resLoc, spec.getLocation());
}

which actually works.

I have two further questions though:

1. Why does an asset need 2 an IResourceLocation and an ILocation? I'm
obviously missing somehting fundamental here.
2. Does this seem like a reasonable solution?

Best regards,

  John

On Tue, 2004-01-27 at 21:25, John Meredith wrote:
> Hi,
> 
> I have a component which contains some images based on the context it
> finds itself in. In my case, the images change depending on the which
> brand a product belongs too, however the images themselves are not
> related to the product in question.
> 
> As I'd like to be able to define a brand dynamically with it's
> associated images, I'm stuck with the resulting image paths (after
> upload).
> 
> My question is thus: Is it at all possible to create ContextAssets
> dynamically and if so how? I'm aware of being able to use the @Any tag
> on an <img>, however I'd also like to use the @Rollover in some cases so
> an IAsset is required (plus I don;t want to rewrite a new @Rollover).
> 
> TIA,
> 
>   John
-- 
John Meredith <ps...@t-online.de>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org