You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by José Paumard <Jo...@orange.fr> on 2008/05/27 12:03:29 UTC

Contributing to the BeanModel

Hello all,

Is it possible de contribute a building method for a special class to 
the BeanModel ?

 From what I understand, the bean editor takes care of the construction 
of new objects, and its method consists of choosing the constructor with 
the greatest number of arguments, and tries to match those arguments 
with known services. I would like to override this behavior, and 
implement my own.

Thank you for your help,

José

Re: Contributing to the BeanModel

Posted by Daniel Jue <te...@gmail.com>.
I am a sole developer on my project, and I am also using Fernando's
approach.  The "form beans" help solve order of data entry and other
dependencies that I just wouldn't want to encode in the persistent
model.  In addition, I've found these "form beans" are a great way to
insert hard coded data and do testing.

i.e.

public void generateSampleReportingUsers() {
		Registration r = new Registration();

		r.setUsername("daniel.jue");
		r.setPassword("urshipmentofFAILhasarrived");
		r.setFirstName("Daniel");
		r.setMiddleInitial("");
		r.setLastName("Jue");
		r.setInstallationAccess("DEMO");
		r.setDatabaseAccess("DEMO");
...
...
		this.addReportingUser(r);
}


On Wed, May 28, 2008 at 4:43 PM, Fernando Padilla <fe...@alum.mit.edu> wrote:
> The design pattern that we are starting to play with is to create beans
> specifically for the forms.  Then write code that ferries the data between
> the form-bean and the actual persistent objects.
>
> This gives you more grunt work, but it adds a point of abstraction and
> flexibility.  For the most part it gives you freedom to construct your
> form/ui differently than the underlying persistent model.  For example, all
> validator/data type annotations are tied to the form-bean instead of the
> underlying persistent model, which might not match cleanly.  Also your
> persistent model might not be what you actually want to expose to the form.
>  Or you can expose a more complicated form which maps to persistent model in
> different ways (multiple objects, etc etc).
>
> At the moment, it's not as "easy" as just giving the bean edit form your
> persistent objects, but I think it's more flexible in the long run.  So it's
> just another option to keep in mind.  You just have to keep your form-beans
> outside of the components/pages packages or you'll have issues with the
> tapestry enhancing classloaders.. We keep them under a forms package..
>
>
> Filip S. Adamsen wrote:
>>
>> Well, you're right. But to me, at least, it's not that big of a deal. The
>> dependency will be to tapestry5-annotations, which is a very small
>> dependency.
>>
>> Anyhow, developing Tapestry apps is just a hobby of mine - for now, anyhow
>> - so I make the decisions myself.
>>
>> Sadly, I don't know of any other way to specify which constructor to use.
>> I suggest you raise a JIRA issue if you want an alternative way to do it.
>>
>> -Filip
>>
>> On 2008-05-28 20:13, José Paumard wrote:
>>>
>>> Hello Filip,
>>>>
>>>> From what I understand, that would involve changing the object model
>>>
>>> (not so nice, I dont have the hand on that), and making a dependency
>>> from this model to T5. I can already hear ppl screaming at that ;)
>>>
>>> Am I right ?
>>> Thank you,
>>>
>>> José
>>>
>>> Filip S. Adamsen a écrit :
>>>>
>>>> Hi José,
>>>>
>>>> You can put @Inject in the constructor you want Tapestry to use for
>>>> auto-instantiation. Should solve your problem.
>>>>
>>>> -Filip
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
> ---------------------------------------------------------------------
> 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: Contributing to the BeanModel

Posted by Fernando Padilla <fe...@alum.mit.edu>.
The design pattern that we are starting to play with is to create beans 
specifically for the forms.  Then write code that ferries the data 
between the form-bean and the actual persistent objects.

This gives you more grunt work, but it adds a point of abstraction and 
flexibility.  For the most part it gives you freedom to construct your 
form/ui differently than the underlying persistent model.  For example, 
all validator/data type annotations are tied to the form-bean instead of 
the underlying persistent model, which might not match cleanly.  Also 
your persistent model might not be what you actually want to expose to 
the form.  Or you can expose a more complicated form which maps to 
persistent model in different ways (multiple objects, etc etc).

At the moment, it's not as "easy" as just giving the bean edit form your 
persistent objects, but I think it's more flexible in the long run.  So 
it's just another option to keep in mind.  You just have to keep your 
form-beans outside of the components/pages packages or you'll have 
issues with the tapestry enhancing classloaders.. We keep them under a 
forms package..


Filip S. Adamsen wrote:
> Well, you're right. But to me, at least, it's not that big of a deal. 
> The dependency will be to tapestry5-annotations, which is a very small 
> dependency.
> 
> Anyhow, developing Tapestry apps is just a hobby of mine - for now, 
> anyhow - so I make the decisions myself.
> 
> Sadly, I don't know of any other way to specify which constructor to 
> use. I suggest you raise a JIRA issue if you want an alternative way to 
> do it.
> 
> -Filip
> 
> On 2008-05-28 20:13, José Paumard wrote:
>> Hello Filip,
>>> From what I understand, that would involve changing the object model
>> (not so nice, I dont have the hand on that), and making a dependency
>> from this model to T5. I can already hear ppl screaming at that ;)
>>
>> Am I right ?
>> Thank you,
>>
>> José
>>
>> Filip S. Adamsen a écrit :
>>> Hi José,
>>>
>>> You can put @Inject in the constructor you want Tapestry to use for 
>>> auto-instantiation. Should solve your problem.
>>>
>>> -Filip
>>
>>
>> ---------------------------------------------------------------------
>> 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
> 

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


Re: Contributing to the BeanModel

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Well, you're right. But to me, at least, it's not that big of a deal. 
The dependency will be to tapestry5-annotations, which is a very small 
dependency.

Anyhow, developing Tapestry apps is just a hobby of mine - for now, 
anyhow - so I make the decisions myself.

Sadly, I don't know of any other way to specify which constructor to 
use. I suggest you raise a JIRA issue if you want an alternative way to 
do it.

-Filip

On 2008-05-28 20:13, José Paumard wrote:
> Hello Filip,
>> From what I understand, that would involve changing the object model
> (not so nice, I dont have the hand on that), and making a dependency
> from this model to T5. I can already hear ppl screaming at that ;)
> 
> Am I right ?
> Thank you,
> 
> José
> 
> Filip S. Adamsen a écrit :
>> Hi José,
>>
>> You can put @Inject in the constructor you want Tapestry to use for 
>> auto-instantiation. Should solve your problem.
>>
>> -Filip
> 
> 
> ---------------------------------------------------------------------
> 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: Contributing to the BeanModel

Posted by José Paumard <Jo...@orange.fr>.
Hello Filip, 

>From what I understand, that would involve changing the object model
(not so nice, I dont have the hand on that), and making a dependency
from this model to T5. I can already hear ppl screaming at that ;)

Am I right ? 

Thank you,

José

Filip S. Adamsen a écrit :
> Hi José,
>
> You can put @Inject in the constructor you want Tapestry to use for 
> auto-instantiation. Should solve your problem.
>
> -Filip


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


Re: Contributing to the BeanModel

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi José,

You can put @Inject in the constructor you want Tapestry to use for 
auto-instantiation. Should solve your problem.

-Filip

On 2008-05-28 15:59, José Paumard wrote:
> Hello Marcus,
> 
> Thank you for your answer, but the customization provided by the 
> BeanModel are about properties, their orders etc... A bean is built by a 
> call to newInstance, defined in the BeanModel interface. The way the 
> bean is built comes from InternalUtils.findAutobuildConstructor. This 
> class choses a constructor with a given algorithm, namely it choses the 
> constructor with the largest number of arguments.
> 
> Then T5 tries to match the arguments it needs with the services it has 
> at hand. This approach is smart, but it would need a major refactoring 
> of the object (old and legacy) model I already have, so I dont want to 
> use it.
> 
> It would be great if I could write something like
> 
>    configuration.add(MyBean.class, "constructor", myBeanConstructor) ;
> 
> to tell T5 what constructor I want to see used for what class, or
> 
>    configuration.add(MyBean.class, BeanModel.class, MyBeanModelImpl.class)
> 
> to tell T5 that for MyBean.class, I want to use the given implementation 
> of bean model, in that case I could overide the newInstance method. But 
> BeanModelImpl is in the internal package, so this would be a less robust 
> approach.
> 
> Thank you,
> 
> José

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


Re: Contributing to the BeanModel

Posted by José Paumard <Jo...@orange.fr>.
Hello Marcus,

Thank you for your answer, but the customization provided by the 
BeanModel are about properties, their orders etc... A bean is built by a 
call to newInstance, defined in the BeanModel interface. The way the 
bean is built comes from InternalUtils.findAutobuildConstructor. This 
class choses a constructor with a given algorithm, namely it choses the 
constructor with the largest number of arguments.

Then T5 tries to match the arguments it needs with the services it has 
at hand. This approach is smart, but it would need a major refactoring 
of the object (old and legacy) model I already have, so I dont want to 
use it.

It would be great if I could write something like

    configuration.add(MyBean.class, "constructor", myBeanConstructor) ;

to tell T5 what constructor I want to see used for what class, or

    configuration.add(MyBean.class, BeanModel.class, MyBeanModelImpl.class)

to tell T5 that for MyBean.class, I want to use the given implementation 
of bean model, in that case I could overide the newInstance method. But 
BeanModelImpl is in the internal package, so this would be a less robust 
approach.

Thank you,

José

Marcus a écrit :
> Hi José,
>
> Maybe this help.
>
> http://tapestry.apache.org/tapestry5/tapestry-core/guide/beaneditform.html
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app3/
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/
>
> Marcus
>
>   


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


Re: Contributing to the BeanModel

Posted by Marcus <mv...@gmail.com>.
Hi José,

Maybe this help.

http://tapestry.apache.org/tapestry5/tapestry-core/guide/beaneditform.html
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app3/
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app3/

Marcus