You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by llonely <at...@gmail.com> on 2007/11/03 19:33:04 UTC

Initialize objects - like in HttpServlet's init()

Hi all,

I am new on Tapestry and try to become familiar with it, mostly through this
forum and the official site. I am trying to migrate a simple servlet into
tapestry.

I find myself search for days for tasks that seem simple. Currently I am
trying to achieve the following:

a) Load some init parameters, located in web.xml. I want to (pre)initialize
them once and have access to them from all pages. In a simple servlet i load
them inside servlet's init() method using ServletConfig. How can I do in on
Tapestry?
b) Similarly with above, I want to load a datasource (configured on tomcat),
only once and use it on all my pages. In a simple servlet I do a Context
lookup in init() method and have the datasource object available. 

So to sum up the question is: how do I preload an object once, and have it
available
for all pages (not inside a session)?


I am using version 5.0.6

Thanks in advance
-- 
View this message in context: http://www.nabble.com/Initialize-objects---like-in-HttpServlet%27s-init%28%29-tf4743945.html#a13565642
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Initialize objects - like in HttpServlet's init()

Posted by thanos <at...@gmail.com>.
Thanks guys!
Will go through the services documentation

BR
Thanos

Filip S. Adamsen-2 wrote:
> 
> llonely skrev:
>> Hi all,
>> 
> 
> Hi,
> 
>> I am new on Tapestry and try to become familiar with it, mostly through
>> this
>> forum and the official site. I am trying to migrate a simple servlet into
>> tapestry.
> 
> While this is a logical approach to trying out something new, Tapestry 
> generally works better if you rewrite your code instead of migrating - 
> so many things are done differently in Tapestry compared to servlets.
> 
>> I find myself search for days for tasks that seem simple. Currently I am
>> trying to achieve the following:
>> 
>> a) Load some init parameters, located in web.xml. I want to
>> (pre)initialize
>> them once and have access to them from all pages. In a simple servlet i
>> load
>> them inside servlet's init() method using ServletConfig. How can I do in
>> on
>> Tapestry?
> 
> I'd suggest using symbols for that:
> http://tapestry.apache.org/tapestry5/tapestry-ioc/symbols.html
> 
>> b) Similarly with above, I want to load a datasource (configured on
>> tomcat),
>> only once and use it on all my pages. In a simple servlet I do a Context
>> lookup in init() method and have the datasource object available. 
> 
> You should definitely create a service for that. If you expose a getter 
> to your datasource as part of the service interface you can use the 
> PropertyShadowBuilder to expose the datasource as its own service, ready 
> for easy injection into your pages:
> http://tapestry.apache.org/tapestry5/tapestry-ioc/shadow.html
> 
>> So to sum up the question is: how do I preload an object once, and have
>> it
>> available
>> for all pages (not inside a session)?
> 
> Services. : )
> 
>> I am using version 5.0.6
>> 
>> Thanks in advance
> 
> Hope this helps.
> 
> -Filip
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Initialize-objects---like-in-HttpServlet%27s-init%28%29-tf4743945.html#a13574817
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: Initialize objects - like in HttpServlet's init()

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
llonely skrev:
> Hi all,
> 

Hi,

> I am new on Tapestry and try to become familiar with it, mostly through this
> forum and the official site. I am trying to migrate a simple servlet into
> tapestry.

While this is a logical approach to trying out something new, Tapestry 
generally works better if you rewrite your code instead of migrating - 
so many things are done differently in Tapestry compared to servlets.

> I find myself search for days for tasks that seem simple. Currently I am
> trying to achieve the following:
> 
> a) Load some init parameters, located in web.xml. I want to (pre)initialize
> them once and have access to them from all pages. In a simple servlet i load
> them inside servlet's init() method using ServletConfig. How can I do in on
> Tapestry?

I'd suggest using symbols for that:
http://tapestry.apache.org/tapestry5/tapestry-ioc/symbols.html

> b) Similarly with above, I want to load a datasource (configured on tomcat),
> only once and use it on all my pages. In a simple servlet I do a Context
> lookup in init() method and have the datasource object available. 

You should definitely create a service for that. If you expose a getter 
to your datasource as part of the service interface you can use the 
PropertyShadowBuilder to expose the datasource as its own service, ready 
for easy injection into your pages:
http://tapestry.apache.org/tapestry5/tapestry-ioc/shadow.html

> So to sum up the question is: how do I preload an object once, and have it
> available
> for all pages (not inside a session)?

Services. : )

> I am using version 5.0.6
> 
> Thanks in advance

Hope this helps.

-Filip

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


Re: Initialize objects - like in HttpServlet's init()

Posted by Ulrich Stärk <ul...@spielviel.de>.
T5 hast its own IoC container incorporated for which you could write a 
new service and have it injected into your page classes using the 
@Inject annotation. For more information consult the Tapestry IoC 
documentation at http://tapestry.apache.org/tapestry5/tapestry-ioc/.

Uli

llonely schrieb:
> Hi all,
> 
> I am new on Tapestry and try to become familiar with it, mostly through this
> forum and the official site. I am trying to migrate a simple servlet into
> tapestry.
> 
> I find myself search for days for tasks that seem simple. Currently I am
> trying to achieve the following:
> 
> a) Load some init parameters, located in web.xml. I want to (pre)initialize
> them once and have access to them from all pages. In a simple servlet i load
> them inside servlet's init() method using ServletConfig. How can I do in on
> Tapestry?
> b) Similarly with above, I want to load a datasource (configured on tomcat),
> only once and use it on all my pages. In a simple servlet I do a Context
> lookup in init() method and have the datasource object available. 
> 
> So to sum up the question is: how do I preload an object once, and have it
> available
> for all pages (not inside a session)?
> 
> 
> I am using version 5.0.6
> 
> Thanks in advance


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