RE: T5 Script component [WAS: Re: T5 page lifecycle]

2007-05-29 Thread Kristian Marinkovic
caching is one advantage of using assets 

another advantage is the possibility to let tapestry decide
how your assets are delivered: plain or compressed

the asset service will determine browser and type 
of asset  to decide  whether  it can use compression. 
(if gzip is accepted :))

jesse did a great job implementing this in Tapestry 4.
Its just a matter of time till its ported to Tapestry 5 :)

see org.apache.tapestry.asset.AssetService in Tapestry 4

g,
kris




Martin Grotzke <[EMAIL PROTECTED]> 
29.05.2007 11:17
Bitte antworten an
"Tapestry users" 


An
Tapestry users 
Kopie

Thema
RE: T5 Script component [WAS: Re: T5 page lifecycle]






On Tue, 2007-05-29 at 09:36 +0200, Kristian Marinkovic wrote:
> instead of resolving the path to your resource manually you can 
> use the asset service (useful when thinking of portlets) 
What exactly is the advantage of using the AssetSource? Is it e.g.
caching or s.th. else?
In respect to the Request that I used I suppose for a portlet
environment it should only be necessary to provide another (portlet
specific) implementation.

Cheers,
Martin


> 
> i wrote a stylesheet component myself that works like your 
> script component :) ... and i enjoyed writing it. 
> 
> 
> public class Script { 
> 
> @Inject 
> private AssetSource assetSource; 
> 
> 
> @BeginRender
>boolean renderMessage( MarkupWriter writer ) { 
> 
>Asset script = assetSource.findAsset(null, _src, null); 
> 
>writer.element( "script",
>"type", _type,
>"src", script.toClientUrl()) 
> } 
> 
> @Component(parameters={"src=context:js/mainFunction.js"}) 
> Script script; 
> 
> 
> g, 
> kris 
> 
> 
> 
> 
> 
> 
> 
> Martin Grotzke
> <[EMAIL PROTECTED]> 
> 
> 26.05.2007 14:40 
> Bitte antworten an
>  "Tapestry users"
> 
> 
> 
> 
> 
>An
> Tapestry users
>  
> Kopie
> 
> Thema
> T5 Script
> component [WAS:
> Re: T5 page
> lifecycle]
> 
> 
> 
> 
> 
> 
> 
> 
> thanx, good to know that.
> 
> Although, I prefer having a template that can be further developed by
> page designers, so I wrote a Script component that can be used like
> this:
> 
>  src="js/main_functions.js"/>
> 
> The script component class:
> 
> public class Script {
> 
>@Inject
>private Request _request;
>@Parameter(required = true, defaultPrefix="literal")
>private String _type;
>@Parameter(required = true, defaultPrefix="literal")
>private String _src;
> 
>@BeginRender
>boolean renderMessage( MarkupWriter writer ) {
>writer.element( "script",
>"type", _type,
>"src", _request.getContextPath() + "/" + _src );
>writer.end();
>return false;
>}
> 
> }
> 
> Is there anything that could be improved?
> 
> Btw: I really love how easy it is to write a component in T5, you
> just have to do what you want, nothing more - really, really nice!!
> 
> Cheers,
> Martin
> 
> 
> 
> On Fri, 2007-05-25 at 10:13 -0700, Howard Lewis Ship wrote:
> > Yes, you can.  The AssetSource service is public, so you can ask it
> for a
> > dynamically determined service.
> > 
> > In 5.0.5 snapshot, you can do the following:
> > 
> > @Inject
> > private Request _request;
> > 
> > public Request getRequest() { return _request; }
> > 
> > public String getLibraryPath() { return ... }
> > 
> > And in the template ...
> > 
> > <body>
> > <script type="text/javascript"
> src="${request.contextPath}/${libraryPath}"/>
> >  ...
> > 
> > 
> > 5.0.5-SNAPSHOT supports expansions inside attributes, even of
> non-component
> > elements, and you can do some simple string-assembly inline.  What
> this
> > doesn't do is ensure that the library exists, or handle localization
> of the
> > library (perhaps more relevant for an image than a JavaScript
> library).
> > 
> > 
> > 
> > On 5/25/07, Martin Grotzke <[EMAIL PROTECTED]> wrote:
> > >
> > > On Fri, 2007-05-25 at 07:54 -0700, Howard Lewis Ship wrote:
> > > > There isn't a component, but you can in your page or component
> class:
> > > >
> > > > @Inject @Path("context:js/main_functions.js")
> > > > private Asset _library;
> > > is it possible

RE: T5 Script component [WAS: Re: T5 page lifecycle]

2007-05-29 Thread Martin Grotzke
On Tue, 2007-05-29 at 09:36 +0200, Kristian Marinkovic wrote:
> instead of resolving the path to your resource manually you can 
> use the asset service (useful when thinking of portlets) 
What exactly is the advantage of using the AssetSource? Is it e.g.
caching or s.th. else?
In respect to the Request that I used I suppose for a portlet
environment it should only be necessary to provide another (portlet
specific) implementation.

Cheers,
Martin


> 
> i wrote a stylesheet component myself that works like your 
> script component :) ... and i enjoyed writing it. 
> 
> 
> public class Script { 
> 
> @Inject 
> private AssetSource assetSource;  
> 
> 
> @BeginRender
>boolean renderMessage( MarkupWriter writer ) { 
> 
>Asset script = assetSource.findAsset(null, _src, null); 
> 
>writer.element( "script",
>"type", _type,
>"src", script.toClientUrl()) 
> } 
> 
> @Component(parameters={"src=context:js/mainFunction.js"}) 
> Script script; 
>  
> 
> g, 
> kris 
>  
> 
> 
> 
> 
> 
> 
> Martin Grotzke
> <[EMAIL PROTECTED]> 
> 
> 26.05.2007 14:40 
> Bitte antworten an
>  "Tapestry users"
> 
> 
> 
> 
> 
>An
> Tapestry users
>  
> Kopie
> 
> Thema
> T5 Script
> component [WAS:
> Re: T5 page
> lifecycle]
> 
> 
> 
> 
> 
> 
> 
> 
> thanx, good to know that.
> 
> Although, I prefer having a template that can be further developed by
> page designers, so I wrote a Script component that can be used like
> this:
> 
>  src="js/main_functions.js"/>
> 
> The script component class:
> 
> public class Script {
>
>@Inject
>private Request _request;
>@Parameter(required = true, defaultPrefix="literal")
>private String _type;
>@Parameter(required = true, defaultPrefix="literal")
>private String _src;
> 
>@BeginRender
>boolean renderMessage( MarkupWriter writer ) {
>writer.element( "script",
>"type", _type,
>"src", _request.getContextPath() + "/" + _src );
>writer.end();
>return false;
>}
>
> }
> 
> Is there anything that could be improved?
> 
> Btw: I really love how easy it is to write a component in T5, you
> just have to do what you want, nothing more - really, really nice!!
> 
> Cheers,
> Martin
> 
> 
> 
> On Fri, 2007-05-25 at 10:13 -0700, Howard Lewis Ship wrote:
> > Yes, you can.  The AssetSource service is public, so you can ask it
> for a
> > dynamically determined service.
> > 
> > In 5.0.5 snapshot, you can do the following:
> > 
> > @Inject
> > private Request _request;
> > 
> > public Request getRequest() { return _request; }
> > 
> > public String getLibraryPath() { return ... }
> > 
> > And in the template ...
> > 
> > 
> >