You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Tuan <mr...@gmail.com> on 2009/03/26 08:09:21 UTC

[T5] Asset Url is changed via domain. Meet Problems when use Alias or AliasOverrides

Hi all,

This is my problems when I use Alias or AliasOverrides. Please help me 
correct them.

_*Context: *_

IndexPage.tml
<html namespace="..."/>
       <t:MyComponent/>
</html>

MyComponent.tml
<t:container namespace="...">
          <img src="${asset:image.gif}" alt="..."/>
</t:container>

-=> url of image.gif is ".../components/image.gif"

In my app - business logic, theme and template are used. They are 
changed via *domain*. It means above image url will change via domain. Ex:
     - If end user go to my app site in "domain1.com", url of image 
should be "..../components/*domain1.com*/image.gif"
     -                     ...                         "domain2.com",   
            ....                  "..../components/*domain2.com*/image.gif"

(domain1 and domain both specify same IP)

_*My solution:*_  Override service AssetSource (trig it to change path)
MyAssetSource.java

public class MyAssetSource extends AssetSourceImpl {
    ...
    @Override
    public Asset getClasspathAsset(String path) {
        path = modifyPath(path); 
        return getClasspathAsset(path, null);
    }
    ...
}


Then, Use MyAssetSource to override T5 AssetSource  service


 binder.bind(AssetSource.class, MyAssetSource.class).withId(
         "MyAssetSource");

 public void contributeAlias(Configuration<AliasContribution> configuration,
            @InjectService("MyAssetSource") AssetSource assetSource) {
        configuration
                .add(AliasContribution.create(AssetSource.class, 
assetSource));
    }




_*Problem:
*_ - T5 throws error when go to index page:
No adapter from type 
org.apache.tapestry5.ioc.internal.util.ClasspathResource to type 
org.apache.tapestry5.services.AssetFactory is available (registered 
types are (none))

_*
*_- In another way, I use contributeAliasOverrides method but I also get 
some errors. Look like I don't know how to use alias and aliasOverride! 
Please tell me how use Alias or contributeAliasOverrides.

Thanks.
_*

*_

Re: [T5] Asset Url is changed via domain. Meet Problems when use Alias or AliasOverrides

Posted by Fernando Padilla <fe...@alum.mit.edu>.
hmm.  Is there an AssetFactory?

Tuan wrote:
> Thanks Fernando Padilla, I created AssetSourceDecorator as you said. The 
> result is
>        + For all assets are accessed by @includestylesheet, 
> @include...., It is ok.
>        + For all assets are accessed in template 
> ${asset:tapestry_banner.gif}, it is ok when end-user go to the page in 
> first time. The time after that,* it is fail, **AssetSourceDecorator is 
> not called **.*  I know assetSourceImpl make cache and check whether 
> cache to asset. But, T5 doesn't call AssetSourceDecorator  when cache 
> for the asset is avaliable. It means that there is a class checked 
> whether cache before. Do you know the class?
> 
> Actually, I met the problems (asset, asset cache ) in last month. At the 
> time, I created a service "AssetHelper" that having a method 
> "getAsset(String path)". When I want to access resource (css, js, image 
> ...), I used the service. It means that some way like that ${asset:...}, 
> @Inject@Path... can not be used
> 
> Now, I see my old way is not convenient. so, I try to solve the problem 
> by using the ways of T5 ( ${asset:tapestry_banner.gif}, ....).
> 
> This is my code:
> ------------------------------------------------------------------------
> public class AssetSourceDecorator implements AssetSource {
>    ...
>    private AssetSource _t5AssetSource;
> 
>    public AssetSourceDecorator(AssetSource assetSource) {          
> logger.info(">>>AssetSourceDecorator");
>        *_t5AssetSource = assetSource;*
>    }
> 
>    public Asset getAsset(Resource baseResource, String path, Locale 
> locale) {
>        logger.info(">>>getAsset " + path );
>       path = modifyPath(path);
>        *return _t5AssetSource.getAsset(baseResource, path, locale);*
>    }
>      ...
> }
> 
> public class AppModule {
>    public static AssetSource decorateAssetSource(AssetSource assetSource) {
>            return new AssetSourceDecorator(assetSource);
>     }
> }
> 
> ------------------------------------------------------------------------
> 
> 
> 
> Fernando Padilla wrote:
>> another thing you can play with, which is sometimes easier to 
>> integrate, is the service decoration.
>>
>> try learning about decorators.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

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


Re: [T5] Asset Url is changed via domain. Meet Problems when use Alias or AliasOverrides

Posted by Tuan <mr...@gmail.com>.
Thanks Fernando Padilla, I created AssetSourceDecorator as you said. The 
result is
        + For all assets are accessed by @includestylesheet, 
@include...., It is ok.
        + For all assets are accessed in template 
${asset:tapestry_banner.gif}, it is ok when end-user go to the page in 
first time. The time after that,* it is fail, **AssetSourceDecorator is 
not called **.*  I know assetSourceImpl make cache and check whether 
cache to asset. But, T5 doesn't call AssetSourceDecorator  when cache 
for the asset is avaliable. It means that there is a class checked 
whether cache before. Do you know the class?

Actually, I met the problems (asset, asset cache ) in last month. At the 
time, I created a service "AssetHelper" that having a method 
"getAsset(String path)". When I want to access resource (css, js, image 
...), I used the service. It means that some way like that ${asset:...}, 
@Inject@Path... can not be used

Now, I see my old way is not convenient. so, I try to solve the problem 
by using the ways of T5 ( ${asset:tapestry_banner.gif}, ....).

This is my code:
------------------------------------------------------------------------
public class AssetSourceDecorator implements AssetSource {
    ...
    private AssetSource _t5AssetSource;

    public AssetSourceDecorator(AssetSource assetSource) {   
        logger.info(">>>AssetSourceDecorator");
        *_t5AssetSource = assetSource;*
    }

    public Asset getAsset(Resource baseResource, String path, Locale 
locale) {
        logger.info(">>>getAsset " + path );
       path = modifyPath(path);
        *return _t5AssetSource.getAsset(baseResource, path, locale);*
    }
      ...
}

public class AppModule {
    public static AssetSource decorateAssetSource(AssetSource assetSource) {
            return new AssetSourceDecorator(assetSource);
     }
}

------------------------------------------------------------------------



Fernando Padilla wrote:
> another thing you can play with, which is sometimes easier to 
> integrate, is the service decoration.
>
> try learning about decorators.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


Re: [T5] Asset Url is changed via domain. Meet Problems when use Alias or AliasOverrides

Posted by Fernando Padilla <fe...@alum.mit.edu>.
another thing you can play with, which is sometimes easier to integrate, 
is the service decoration.

try learning about decorators.


On 3/26/09 12:09 AM, Tuan wrote:
> Hi all,
>
> This is my problems when I use Alias or AliasOverrides. Please help me
> correct them.
>
> _*Context: *_
>
> IndexPage.tml
> <html namespace="..."/>
> <t:MyComponent/>
> </html>
>
> MyComponent.tml
> <t:container namespace="...">
> <img src="${asset:image.gif}" alt="..."/>
> </t:container>
>
> -=> url of image.gif is ".../components/image.gif"
>
> In my app - business logic, theme and template are used. They are
> changed via *domain*. It means above image url will change via domain. Ex:
> - If end user go to my app site in "domain1.com", url of image should be
> "..../components/*domain1.com*/image.gif"
> - ... "domain2.com", .... "..../components/*domain2.com*/image.gif"
>
> (domain1 and domain both specify same IP)
>
> _*My solution:*_ Override service AssetSource (trig it to change path)
> MyAssetSource.java
>
> public class MyAssetSource extends AssetSourceImpl {
> ...
> @Override
> public Asset getClasspathAsset(String path) {
> path = modifyPath(path); return getClasspathAsset(path, null);
> }
> ...
> }
>
>
> Then, Use MyAssetSource to override T5 AssetSource service
>
>
> binder.bind(AssetSource.class, MyAssetSource.class).withId(
> "MyAssetSource");
>
> public void contributeAlias(Configuration<AliasContribution> configuration,
> @InjectService("MyAssetSource") AssetSource assetSource) {
> configuration
> .add(AliasContribution.create(AssetSource.class, assetSource));
> }
>
>
>
>
> _*Problem:
> *_ - T5 throws error when go to index page:
> No adapter from type
> org.apache.tapestry5.ioc.internal.util.ClasspathResource to type
> org.apache.tapestry5.services.AssetFactory is available (registered
> types are (none))
>
> _*
> *_- In another way, I use contributeAliasOverrides method but I also get
> some errors. Look like I don't know how to use alias and aliasOverride!
> Please tell me how use Alias or contributeAliasOverrides.
>
> Thanks.
> _*
>
> *_
>

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