I'd just inject all three assets and choose which one to return. Injection is cheap. Maybe your situation is actually more complex.
On Nov 19, 2007 5:51 PM, Doublel <[EMAIL PROTECTED]> wrote: > Yes it works well.Thanks very much > complete code : > > @Inject > private ComponentResources resource; > @Inject > private AssetSource assetSource; > > > private Asset weatherImagePath; > > /** > * @param weatherImagePath the weatherImagePath to set > */ > public void setWeatherImagePath(Asset weatherImagePath) { > this.weatherImagePath = weatherImagePath; > } > > public Asset getWeatherImagePath(){ > > > return this.assetSource.findAsset( > this.resource.getBaseResource(), > "context:images/weather/"+this.weatherPath, null); > } > > public void onActivate(String id){ > //bc is load from DB > if (lw.hnSunny.equals(bc.getLogWeather())){ > this.weatherPath="hn2_sunny.gif"; > > }else if (lw.hnIce.equals(bc.getLogWeather())) > { > this.weatherPath="hn2_ice.gif"; > }else if (lw.hnCloudy.equals(bc.getLogWeather())) > { > this.weatherPath="hn2_cloudy.gif"; > } > > } > > > 2007/11/20, Josh Canfield <[EMAIL PROTECTED]>: > > > > > Injecting the asset as you've done doesn't make a lot of sense since the > > annotation @Path is a compile time construct. So what you are getting in > > your annotation is probably null, or whatever your default for weatherPath > > was. > > > > The advantage to using AssetResource is that you can look up assets at > > runtime... > > > > Josh > > > > On Nov 19, 2007 5:34 AM, Chris Lewis <[EMAIL PROTECTED]> wrote: > > > > > I've not seen AssetResource - what is the advantage to using it like > > > this as opposed simply to injecting the asset? > > > > > > lasitha wrote: > > > > On Nov 19, 2007 2:37 PM, Doublel <[EMAIL PROTECTED]> wrote: > > > > > > > >> public void onActivate(String id){ > > > >> if (lw.hnSunny.equals(bc.getLogWeather())){ > > > >> this.weatherPath="logweath.gif"; > > > >> ... > > > >> @Inject > > > >> @Path("context:/images/"+ weatherPath ) > > > >> private Asset trackback; > > > >> > > > >> I want to implement image can dynamic by var weatherPath > > > >> > > > > > > > > Hello, i'd try injecting the AssetSource service directly into your > > > > page/component and using it to look up the resource dynamically. > > > > > > > > > http://tapestry.apache.org/tapestry5/tapestry-core/apidocs/org/apache/tapestry/services/AssetSource.html > > > > > > > > I haven't tested this, but something like: > > > > > > > > @Inject ComponentResources resources; > > > > @Inject AssetSource assetSource; > > > > > > > > Asset getTrackback() { > > > > return assetSource.findAsset( > > > > resources.getBaseResource(), > > > > "context:/images/" + calculateWeatherPath(), > > > > null); > > > > } > > > > > > > > It actually may work with just null for the first parameter (the > > > > resource base) too. > > > > > > > > Cheers, > > > > lasitha > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > > > > > > > > -- > > -- > > TheDailyTube.com. Sign up and get the best new videos on the internet > > delivered fresh to your inbox. > > > > > > -- > 得与失都是生活 > -- Howard M. Lewis Ship Partner and Senior Architect at Feature50 Creator Apache Tapestry and Apache HiveMind