Re: [T5.2] Constructor issue

2010-10-06 Thread Michal Gruca


Howard Lewis Ship wrote:
 
 Remember that you can place @Inject on the constructor that should be
 used if there's any ambiguity.
 

That is what I was looking for. Thanks :)
and +1 for adding that to FAQ :)
-- 
View this message in context: 
http://tapestry-users.832.n2.nabble.com/T5-2-Constructor-issue-tp5603058p5605989.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

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



Re: [T5.2] Constructor issue

2010-10-05 Thread Thiago H. de Paula Figueiredo
On Tue, 05 Oct 2010 10:09:09 -0300, Michal Gruca michalgr...@gmail.com  
wrote:



Hi all.


Hi!


After removing parametrized constructor,
error disappeared. It's bit odd IMHO.


That's documented behavior:  
http://tapestry.apache.org/tapestry5.1/guide/appstate.html. This page is  
for 5.1, but it should be the same for 5.2. Summary: Tapestry uses the  
same logic for choosing a constructor used by Tapestry IoC. That page  
shows you how to control the way you classes are instantiated.



Tapestry should be capable to
instantiate objects that have more than one constructor.


The problem here is: which constructor should be used? Tapestry IoC  
chooses the one with the most parameters.


--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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



Re: [T5.2] Constructor issue

2010-10-05 Thread Michal Gruca

I must disagree. 
But first to clarify. I described two cases.
1. BeanEditForm that cannot instantiate my object
2. Same issue for SSO creating java.util.Date

AD 1.
Quote from BeanEditForm doc:
Often, the BeanEditForm can create the object as needed (assuming a public,
no arguments constructor). 
So i provided such constructor in my entity (public no agrs) + I added
another one that taken String and custom enum. What I assumed was that T5
will just use the one that it can use and leave other one alone. Due to that
behavior no object handled to BeanEditForm should have more constructors
than default one, or should be always created manually, and that is bit more
than user need to do.

Ad 2.
Quote from linked documentation:
The first time you access an SSO, it is created automatically. Typically,
the SSO will have a public no-args constructor ... but you may inject
dependencies into the SSO via its constructor, as you can with a Tapestry
IoC service implementation.
In this case I wanted to use Date. Maybe not some real case scenario, so
let's think about shoping basket for example. It may have default no args
for T5 and second one if I want to instantiate it with some products. If T5
always takes constructor with most arguments it will fail on that scenario
also, meaning that I will have to check boolean variable companion exist on
every page on which I wan't to use my object.
IMHO the best would be try to use no-args constructor or use one with most
args and if You fail try another one and another till You succeed (meaning
reach default no-args or error when there is no default no-args
constructor).

Regards
Michał
-- 
View this message in context: 
http://tapestry-users.832.n2.nabble.com/T5-2-Constructor-issue-tp5603058p5603560.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

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



Re: [T5.2] Constructor issue

2010-10-05 Thread Thiago H. de Paula Figueiredo
On Tue, 05 Oct 2010 12:17:46 -0300, Michal Gruca michalgr...@gmail.com  
wrote:



I must disagree.
But first to clarify. I described two cases.
1. BeanEditForm that cannot instantiate my object


BeanEditor (used internally for BeanEditForm) uses the no-args constructor  
if it exists. I apologize for not making this distinction clear.



2. Same issue for SSO creating java.util.Date


ApplicationStateManager(Impl) uses ObjectLocator.autobuild() to construct  
instances.



Ad 2.
Quote from linked documentation:
The first time you access an SSO, it is created automatically.  
Typically, the SSO will have a public no-args constructor ... but you  
may inject

dependencies into the SSO via its constructor, as you can with a Tapestry
IoC service implementation.
In this case I wanted to use Date. Maybe not some real case scenario, so
let's think about shoping basket for example. It may have default no args
for T5 and second one if I want to instantiate it with some products. If  
T5 always takes constructor with most arguments it will fail on that  
scenario
also, meaning that I will have to check boolean variable companion exist  
on every page on which I wan't to use my object.


In this case, use @SessionState(create = false) so the field is null when  
it's not in the session. and you don't need to declare a boolean variable.


--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor

Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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



Re: [T5.2] Constructor issue

2010-10-05 Thread Josh Canfield
 Often, the BeanEditForm can create the object as needed (assuming a public,
 no arguments constructor). 
I believe the java docs are out of date. The change happened in a
dependent class and the docs don't reflect the change. As Thiago said,
the current strategy is to try to make the most complete object is
built based on the available constructors. This lets you build beans
that have access to services via constructor injection (like a
service).

I think failing to pick the correct constructor is a defect that
Tapestry *should* solve.  Principle 2 is Adaptive API, which should
adapt to your code. One option is to try them until you get one that
works... this could lead to frustration during development if it's not
obvious which constructor is getting called...

Date has multiple constructors, so this is essentially the same problem.

Josh

On Tue, Oct 5, 2010 at 8:17 AM, Michal Gruca michalgr...@gmail.com wrote:

 I must disagree.
 But first to clarify. I described two cases.
 1. BeanEditForm that cannot instantiate my object
 2. Same issue for SSO creating java.util.Date

 AD 1.
 Quote from BeanEditForm doc:
 Often, the BeanEditForm can create the object as needed (assuming a public,
 no arguments constructor). 
 So i provided such constructor in my entity (public no agrs) + I added
 another one that taken String and custom enum. What I assumed was that T5
 will just use the one that it can use and leave other one alone. Due to that
 behavior no object handled to BeanEditForm should have more constructors
 than default one, or should be always created manually, and that is bit more
 than user need to do.

 Ad 2.
 Quote from linked documentation:
 The first time you access an SSO, it is created automatically. Typically,
 the SSO will have a public no-args constructor ... but you may inject
 dependencies into the SSO via its constructor, as you can with a Tapestry
 IoC service implementation.
 In this case I wanted to use Date. Maybe not some real case scenario, so
 let's think about shoping basket for example. It may have default no args
 for T5 and second one if I want to instantiate it with some products. If T5
 always takes constructor with most arguments it will fail on that scenario
 also, meaning that I will have to check boolean variable companion exist on
 every page on which I wan't to use my object.
 IMHO the best would be try to use no-args constructor or use one with most
 args and if You fail try another one and another till You succeed (meaning
 reach default no-args or error when there is no default no-args
 constructor).

 Regards
 Michał
 --
 View this message in context: 
 http://tapestry-users.832.n2.nabble.com/T5-2-Constructor-issue-tp5603058p5603560.html
 Sent from the Tapestry Users mailing list archive at Nabble.com.

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





-- 
--
http://www.bodylabgym.com - a private, by appointment only, one-on-one
health and fitness facility.
--
http://www.ectransition.com - Quality Electronic Cigarettes at a
reasonable price!
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

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



Re: [T5.2] Constructor issue

2010-10-05 Thread Howard Lewis Ship
Your are correct and this has been the behavior since at least 5.1.

On Tue, Oct 5, 2010 at 9:21 AM, Josh Canfield joshcanfi...@gmail.com wrote:

 BeanEditor (used internally for BeanEditForm) uses the no-args constructor
 if it exists. I apologize for not making this distinction clear.


 I'm looking at the 5.2 source and BeanEditor uses the BeanModel to get
 the instance, calls newInstance() which also uses the
 ObjectLocator.autobuild

 On Tue, Oct 5, 2010 at 8:32 AM, Thiago H. de Paula Figueiredo
 thiag...@gmail.com wrote:
 On Tue, 05 Oct 2010 12:17:46 -0300, Michal Gruca michalgr...@gmail.com
 wrote:

 I must disagree.
 But first to clarify. I described two cases.
 1. BeanEditForm that cannot instantiate my object

 BeanEditor (used internally for BeanEditForm) uses the no-args constructor
 if it exists. I apologize for not making this distinction clear.

 2. Same issue for SSO creating java.util.Date

 ApplicationStateManager(Impl) uses ObjectLocator.autobuild() to construct
 instances.

 Ad 2.
 Quote from linked documentation:
 The first time you access an SSO, it is created automatically. Typically,
 the SSO will have a public no-args constructor ... but you may inject
 dependencies into the SSO via its constructor, as you can with a Tapestry
 IoC service implementation.
 In this case I wanted to use Date. Maybe not some real case scenario, so
 let's think about shoping basket for example. It may have default no args
 for T5 and second one if I want to instantiate it with some products. If
 T5 always takes constructor with most arguments it will fail on that
 scenario
 also, meaning that I will have to check boolean variable companion exist
 on every page on which I wan't to use my object.

 In this case, use @SessionState(create = false) so the field is null when
 it's not in the session. and you don't need to declare a boolean variable.

 --
 Thiago H. de Paula Figueiredo
 Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
 instructor
 Owner, Ars Machina Tecnologia da Informação Ltda.
 http://www.arsmachina.com.br

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





 --
 --
 http://www.bodylabgym.com - a private, by appointment only, one-on-one
 health and fitness facility.
 --
 http://www.ectransition.com - Quality Electronic Cigarettes at a
 reasonable price!
 --
 TheDailyTube.com. Sign up and get the best new videos on the internet
 delivered fresh to your inbox.

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





-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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



Re: [T5.2] Constructor issue

2010-10-05 Thread Howard Lewis Ship
Remember that you can place @Inject on the constructor that should be
used if there's any ambiguity.

On Tue, Oct 5, 2010 at 9:22 AM, Howard Lewis Ship hls...@gmail.com wrote:
 Your are correct and this has been the behavior since at least 5.1.

 On Tue, Oct 5, 2010 at 9:21 AM, Josh Canfield joshcanfi...@gmail.com wrote:

 BeanEditor (used internally for BeanEditForm) uses the no-args constructor
 if it exists. I apologize for not making this distinction clear.


 I'm looking at the 5.2 source and BeanEditor uses the BeanModel to get
 the instance, calls newInstance() which also uses the
 ObjectLocator.autobuild

 On Tue, Oct 5, 2010 at 8:32 AM, Thiago H. de Paula Figueiredo
 thiag...@gmail.com wrote:
 On Tue, 05 Oct 2010 12:17:46 -0300, Michal Gruca michalgr...@gmail.com
 wrote:

 I must disagree.
 But first to clarify. I described two cases.
 1. BeanEditForm that cannot instantiate my object

 BeanEditor (used internally for BeanEditForm) uses the no-args constructor
 if it exists. I apologize for not making this distinction clear.

 2. Same issue for SSO creating java.util.Date

 ApplicationStateManager(Impl) uses ObjectLocator.autobuild() to construct
 instances.

 Ad 2.
 Quote from linked documentation:
 The first time you access an SSO, it is created automatically. Typically,
 the SSO will have a public no-args constructor ... but you may inject
 dependencies into the SSO via its constructor, as you can with a Tapestry
 IoC service implementation.
 In this case I wanted to use Date. Maybe not some real case scenario, so
 let's think about shoping basket for example. It may have default no args
 for T5 and second one if I want to instantiate it with some products. If
 T5 always takes constructor with most arguments it will fail on that
 scenario
 also, meaning that I will have to check boolean variable companion exist
 on every page on which I wan't to use my object.

 In this case, use @SessionState(create = false) so the field is null when
 it's not in the session. and you don't need to declare a boolean variable.

 --
 Thiago H. de Paula Figueiredo
 Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and
 instructor
 Owner, Ars Machina Tecnologia da Informação Ltda.
 http://www.arsmachina.com.br

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





 --
 --
 http://www.bodylabgym.com - a private, by appointment only, one-on-one
 health and fitness facility.
 --
 http://www.ectransition.com - Quality Electronic Cigarettes at a
 reasonable price!
 --
 TheDailyTube.com. Sign up and get the best new videos on the internet
 delivered fresh to your inbox.

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





 --
 Howard M. Lewis Ship

 Creator of Apache Tapestry

 The source for Tapestry training, mentoring and support. Contact me to
 learn how I can get you up and productive in Tapestry fast!

 (971) 678-5210
 http://howardlewisship.com




-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

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



RE: [T5.2] Constructor issue

2010-10-05 Thread Jim O'Callaghan
I thought you should annotate the constructor you want the BEF to use with:

@Inject

... to let Tap know which constructor to use.

Regards,
Jim.

-Original Message-
From: Michal Gruca [mailto:michalgr...@gmail.com] 
Sent: 05 October 2010 14:09
To: users@tapestry.apache.org
Subject: [T5.2] Constructor issue


Hi all.
While preparing small showcase app, odd problem came out. When I created
domain object with two constructors (first was default NOOP, second one had
two parameters string and enum, it was meant for manual initialization only)
and tried to use it with beaneditform I received exception that tapestry
cannot handle my object creation. After removing parametrized constructor,
error disappeared. It's bit odd IMHO. Tapestry should be capable to
instantiate objects that have more than one constructor. Also @SessionState
behaved weirdly. I was annotating java.util.Date. Error came up if I haven't
instantiate object manually. Date has default constructor so Tapestry should
be fine with constructing new Date on it's own.
Maybe there are some reasons for that kind of behavior, but as I see it
those are bugs. Should I create jira ticket for that?

Tested on tapestry 5.2.1-snapshot. Link to application sources:
https://bitbucket.org/mgruca/tjug_tapestry_30.09.10/downloads  (last
revision or two were stripped out from additional constructors. Content may
be in Polish, but code should be all in En)
-- 
View this message in context:
http://tapestry-users.832.n2.nabble.com/T5-2-Constructor-issue-tp5603058p560
3058.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

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



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