You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Howard M. Lewis Ship" <hl...@comcast.net> on 2004/02/06 18:39:07 UTC

RE: Dynamic ContextAsset?

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