You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by xfile80303 <le...@grokers.net> on 2009/07/28 23:37:06 UTC

[T5.1] Avoiding "new"

Hi all,

I've some lack of understanding about Tapestry IOC and creating new objects.

I understand the binding of service interfaces with service implementations
and the injection of these services where needed, and this is a great tool.

What I'm missing is a way to auto build or inject (or whatever the
appropriate terminology is) objects which are not services.

A concrete example is:

I have a User interface and a UserImpl implementation.  An object of type
User will be a Session State object.  How can I tell Tapestry IOC to create
a new UserImpl object when it needs to create a User object when I ask the
SessionStateManager for a User.class object?

Another example is:

I have a set of page classes which share some common functionality.  Rather
than have them use a common base class, I want to be able to give them each
an instance of a class which encompasses the common functionality.  I can't
create a new instance of this shared functionality class myself in the page
constructor, and this shared functionality can not be a Service because I
need an instance per page.  How can I get Tapestry to allow me to get an
instance (a replacement for "new")?

Thanks, and sorry if these are silly questions... I'm in the forest and
can't see the trees.

Levi

-- 
View this message in context: http://n2.nabble.com/-T5.1--Avoiding-%22new%22-tp3346190p3346190.html
Sent from the Tapestry Users 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: [T5.1] Avoiding "new"

Posted by xfile80303 <le...@grokers.net>.
It's not horrible for me, but there are two issues:

1) I miss out on the autobuilding that Tapestry can do, and have to pass
around parameters to initialize my User object whenever I need to create one
(such as services, etc.).

2) I want to avoid using new for my own classes to avoid classloader issues
inside Tapestry.

Cheers,

Levi


Sergey Didenko wrote:
> 
> Is it so bad to create new session user using explicit "new"?
> 
> Regards, Sergey.
> 
> 

-- 
View this message in context: http://n2.nabble.com/-T5.1--Avoiding-%22new%22-tp3346190p3350456.html
Sent from the Tapestry Users 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: [T5.1] Avoiding "new"

Posted by Sergey Didenko <se...@gmail.com>.
Is it so bad to create new session user using explicit "new"?

Regards, Sergey.

Re: [T5.1] Avoiding "new"

Posted by xfile80303 <le...@grokers.net>.
Thanks guys...

It looks like ApplicationState objects are treated differently than
services...  see the bottom of this page "Configuring SSOs":

http://tapestry.apache.org/tapestry5.1/guide/appstate.html

I've also walked through the Tapestry code, and there's no binding lookup
for application state objects... it simply goes by the class of the object.

So it sounds like I'll need to use the contributeApplicationStateManager for
my SSO object, and potentially Thiago's recommendation for my second
example.

I'll play with it tomorrow...

Levi


xfile80303 wrote:
> 
> Thanks Thiago,
> 
> Your insight, as always, is appreciated.
> 
> Unfortunately there seems to be a snag...
> 
> In my page I have this:
> 
> 	@SessionState
> 	private User ssUser;
> 
> In my Module I have this:
> 
> 	public static void bind(ServiceBinder binder)
> 	{
> 		//...
> 		binder.bind(User.class, UserImpl.class);
> 		//...
> 	}
> 
> (I've commented out the contribution of the new service scope for now)
> 
> and I get this:
> 
> org.apache.tapestry5.runtime.ComponentEventException
> Class com.java.dse.cwp.eos.idm.User does not contain a public constructor
> needed to autobuild.
> 
> It's as if Tapestry does not recognize the binding.  Other bindings I have
> work as expected... is there something special about SessionState objects?
> 
> BTW, User and UserImpl are in my services package, with my other, working,
> bound services.
> 
> Thanks,
> 
> Levi
> 
> 
> Thiago H. de Paula Figueiredo wrote:
>> 
>> Hi!
>> 
>> I guess you need a new service scope. Tapestry-IoC provides two  
>> out-of-the-box: singleton (default) and per-thread (one object created
>> for  
>> each different thread). You can add a new lifecycle that always returns a  
>> new object. In Spring, this is called the prototype scope.  
>> http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ioc/annotations/Scope.html  
>> will give you some hints about how to add new scopes.
>> 
>> A less elegant solution is to inject ObjectLocator and use its
>> autobuild()  
>> method.
>> 
>> -- 
>> Thiago H. de Paula Figueiredo
>> Independent Java consultant, developer, and instructor
>> http://www.arsmachina.com.br/thiago
>> 
>> ---------------------------------------------------------------------
>> 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://n2.nabble.com/-T5.1--Avoiding-%22new%22-tp3346190p3346777.html
Sent from the Tapestry Users 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: [T5.1] Avoiding "new"

Posted by Olle Hallin <ol...@gmail.com>.
Have a look at the ApplicationStateManager. It is responsible for
instantiating SessionStateObjects (aka ApplicationStateObjects), that can't
be created with new.

HTH,
Olle


2009/7/29 xfile80303 <le...@grokers.net>

>
> Thanks Thiago,
>
> Your insight, as always, is appreciated.
>
> Unfortunately there seems to be a snag...
>
> In my page I have this:
>
>        @SessionState
>        private User ssUser;
>
> In my Module I have this:
>
>        public static void bind(ServiceBinder binder)
>        {
>                //...
>                binder.bind(User.class, UserImpl.class);
>                //...
>        }
>
> (I've commented out the contribution of the new service scope for now)
>
> and I get this:
>
> org.apache.tapestry5.runtime.ComponentEventException
> Class com.java.dse.cwp.eos.idm.User does not contain a public constructor
> needed to autobuild.
>
> It's as if Tapestry does not recognize the binding.  Other bindings I have
> work as expected... is there something special about SessionState objects?
>
> BTW, User and UserImpl are in my services package, with my other, working,
> bound services.
>
> Thanks,
>
> Levi
>
>
> Thiago H. de Paula Figueiredo wrote:
> >
> > Hi!
> >
> > I guess you need a new service scope. Tapestry-IoC provides two
> > out-of-the-box: singleton (default) and per-thread (one object created
> for
> > each different thread). You can add a new lifecycle that always returns a
> > new object. In Spring, this is called the prototype scope.
> >
> http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ioc/annotations/Scope.html
> > will give you some hints about how to add new scopes.
> >
> > A less elegant solution is to inject ObjectLocator and use its
> autobuild()
> > method.
> >
> > --
> > Thiago H. de Paula Figueiredo
> > Independent Java consultant, developer, and instructor
> > http://www.arsmachina.com.br/thiago
> >
> > ---------------------------------------------------------------------
> > 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://n2.nabble.com/-T5.1--Avoiding-%22new%22-tp3346190p3346523.html
> Sent from the Tapestry Users 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
>
>


-- 
Olle Hallin
Senior Java Developer and Architect
olle.hallin@crisp.se
www.crisp.se

Re: [T5.1] Avoiding "new"

Posted by Felix Gonschorek <fe...@ggmedia.net>.
maybe the service "ObjectLocator" will help you too - it creates objects and 
injects services into them, event if they are not services that are known to the 
registry via its "autobuild" method.

xfile80303 schrieb:
> Thanks Thiago,
> 
> Your insight, as always, is appreciated.
> 
> Unfortunately there seems to be a snag...
> 
> In my page I have this:
> 
> 	@SessionState
> 	private User ssUser;
> 
> In my Module I have this:
> 
> 	public static void bind(ServiceBinder binder)
> 	{
> 		//...
> 		binder.bind(User.class, UserImpl.class);
> 		//...
> 	}
> 
> (I've commented out the contribution of the new service scope for now)
> 
> and I get this:
> 
> org.apache.tapestry5.runtime.ComponentEventException
> Class com.java.dse.cwp.eos.idm.User does not contain a public constructor
> needed to autobuild.
> 
> It's as if Tapestry does not recognize the binding.  Other bindings I have
> work as expected... is there something special about SessionState objects?
> 
> BTW, User and UserImpl are in my services package, with my other, working,
> bound services.
> 
> Thanks,
> 
> Levi
> 
> 
> Thiago H. de Paula Figueiredo wrote:
>> Hi!
>>
>> I guess you need a new service scope. Tapestry-IoC provides two  
>> out-of-the-box: singleton (default) and per-thread (one object created for  
>> each different thread). You can add a new lifecycle that always returns a  
>> new object. In Spring, this is called the prototype scope.  
>> http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ioc/annotations/Scope.html  
>> will give you some hints about how to add new scopes.
>>
>> A less elegant solution is to inject ObjectLocator and use its autobuild()  
>> method.
>>
>> -- 
>> Thiago H. de Paula Figueiredo
>> Independent Java consultant, developer, and instructor
>> http://www.arsmachina.com.br/thiago
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
> 

-- 
Felix Gonschorek
ggmedia

Kirchstr. 18
69115 Heidelberg

Tel:   +49 6221 187 44 10
Fax:   +49 6221 187 44 99
Mobil: +49 176 2234 1338

felix@ggmedia.net
http://www.ggmedia.net

Vertretungsberechtigte Gesellschafter:
Felix Gonschorek & Jochen Greiner

Umsatzsteuer-Identifikationsnummer
gemäß § 27a Umsatzsteuergesetz:
DE232906440

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


Re: [T5.1] Avoiding "new"

Posted by xfile80303 <le...@grokers.net>.
Thanks Thiago,

Your insight, as always, is appreciated.

Unfortunately there seems to be a snag...

In my page I have this:

	@SessionState
	private User ssUser;

In my Module I have this:

	public static void bind(ServiceBinder binder)
	{
		//...
		binder.bind(User.class, UserImpl.class);
		//...
	}

(I've commented out the contribution of the new service scope for now)

and I get this:

org.apache.tapestry5.runtime.ComponentEventException
Class com.java.dse.cwp.eos.idm.User does not contain a public constructor
needed to autobuild.

It's as if Tapestry does not recognize the binding.  Other bindings I have
work as expected... is there something special about SessionState objects?

BTW, User and UserImpl are in my services package, with my other, working,
bound services.

Thanks,

Levi


Thiago H. de Paula Figueiredo wrote:
> 
> Hi!
> 
> I guess you need a new service scope. Tapestry-IoC provides two  
> out-of-the-box: singleton (default) and per-thread (one object created for  
> each different thread). You can add a new lifecycle that always returns a  
> new object. In Spring, this is called the prototype scope.  
> http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ioc/annotations/Scope.html  
> will give you some hints about how to add new scopes.
> 
> A less elegant solution is to inject ObjectLocator and use its autobuild()  
> method.
> 
> -- 
> Thiago H. de Paula Figueiredo
> Independent Java consultant, developer, and instructor
> http://www.arsmachina.com.br/thiago
> 
> ---------------------------------------------------------------------
> 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://n2.nabble.com/-T5.1--Avoiding-%22new%22-tp3346190p3346523.html
Sent from the Tapestry Users 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: [T5.1] Avoiding "new"

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Hi!

I guess you need a new service scope. Tapestry-IoC provides two  
out-of-the-box: singleton (default) and per-thread (one object created for  
each different thread). You can add a new lifecycle that always returns a  
new object. In Spring, this is called the prototype scope.  
http://tapestry.apache.org/tapestry5.1/apidocs/org/apache/tapestry5/ioc/annotations/Scope.html  
will give you some hints about how to add new scopes.

A less elegant solution is to inject ObjectLocator and use its autobuild()  
method.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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