Using object or id in Context

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Using object or id in Context

Mats Andersson-2
Why are most examples written as context="myObject.id"?
Should not the best practice be to use the object directly? This way the
handler method will be more type safe. Do you know of any good
best-practices page for issues like this one?

/Tapestry learner


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Using object or id in Context

Peter Stavrinides
Hi Mats,

> Should not the best practice be to use the object directly?
Imho no, myObject.id is a bean for the page (object with empty constructor), which is less error prone. Its nearly always better to use a bean to seperate concerns for cleaner, more maintainable code. I.e.: you should not mix database access with view logic, instead use a single bean where possible per page and handle database access in your services (which makes things more testable and reusable)... so it has several advantages.

The bean is like a glue layer (or the view layer in the MVC pattern). So following this pattern means myObject.id is no less type safe as myObject is never really going to be null in your page.

regards,
Peter


----- Original Message -----
From: "Mats Andersson" <[hidden email]>
To: "Tapestry users" <[hidden email]>
Sent: Thursday, 3 September, 2009 15:58:20 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: Using object or id in Context

Why are most examples written as context="myObject.id"?
Should not the best practice be to use the object directly? This way the
handler method will be more type safe. Do you know of any good
best-practices page for issues like this one?

/Tapestry learner


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Using object or id in Context

Mats Andersson-2
Thanks Peter for the reply. I am starting to learning the concepts of
Tapestry, but it takes time to be productive with it. This mailing list
is a great resource and I hope that I will be able to contribute to it
once I have learned more.

Regards,
Mats

[hidden email] wrote:

> Hi Mats,
>
>  
>> Should not the best practice be to use the object directly?
>>    
> Imho no, myObject.id is a bean for the page (object with empty constructor), which is less error prone. Its nearly always better to use a bean to seperate concerns for cleaner, more maintainable code. I.e.: you should not mix database access with view logic, instead use a single bean where possible per page and handle database access in your services (which makes things more testable and reusable)... so it has several advantages.
>
> The bean is like a glue layer (or the view layer in the MVC pattern). So following this pattern means myObject.id is no less type safe as myObject is never really going to be null in your page.
>
> regards,
> Peter
>
>
> ----- Original Message -----
> From: "Mats Andersson" <[hidden email]>
> To: "Tapestry users" <[hidden email]>
> Sent: Thursday, 3 September, 2009 15:58:20 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
> Subject: Using object or id in Context
>
> Why are most examples written as context="myObject.id"?
> Should not the best practice be to use the object directly? This way the
> handler method will be more type safe. Do you know of any good
> best-practices page for issues like this one?
>
> /Tapestry learner
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Using object or id in Context

Thiago H de Paula Figueiredo
In reply to this post by Mats Andersson-2
Em Thu, 03 Sep 2009 09:58:20 -0300, Mats Andersson  
<[hidden email]> escreveu:

> Why are most examples written as context="myObject.id"?
> Should not the best practice be to use the object directly? This way the  
> handler method will be more type safe. Do you know of any good  
> best-practices page for issues like this one?

Because the object would be coerced to a String. Then you would need to  
get this String and get the original object back.

In Tapestry CRUD, an open source package I'm developing, there's an  
ActivationContextEncoder. It's similar to a ValueEncoder, but used  
specifically for activation context values. Then I have some components  
(ActivationContextPageLink, ActivationContextActionLink) that receives an  
Object and uses the corresponding ActivationContextEncoder to get the  
object's activation context value.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]