You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by sa...@women-at-work.org on 2005/06/09 10:07:38 UTC

Is that the way to do it ?

Hello everyone!

My User class has a field called gender which is 0 or 1 for male or female.
In order to display it as an Icon for "male" or "female" I am using the
following approach and i wonder whether that is good practise and
thread-safe etc...

My hibernate class is called HibernateUser

I have an additional class called User which looks like that:


class User {

private int gender;
private HibernateUser hibernateUser;

public User (HibernateUser hibernateUser){
this.hibernateUser=hibernateUser;
}

public String getIcon(){
if (gender.equals(0)){
return "male.gif";
}
else {
return "female.gif";
}

}

// + setter/getter for the private variables

}

Is that ok ?

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


Re: Is that the way to do it ?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jun 9, 2005, at 9:02 AM, sarah.simbad@women-at-work.org wrote:

> Ok, I agree. For a simple image it is the way to do it.
>
> But what, if it is some piece of html, that is generated from several
> attributes from the User class ?
>
> Something like:
>
> <a href="some link">Firstname, Lastname, age </a>
>
> Or would you create an extra component for that?

It all depends on how frequently something like this is used.   
Pragmatically, if it's only on one page, I'd either do it purely in  
the template, an OGNL expression, or a simple Java getter.  If it is  
used on a couple of pages, I might make a Global method that took a  
User object and formatted the name.  If it was pervasive, a custom  
component would be a wise choice.

One size does not fit all.  Start simple and only for the case(s) you  
need it for, and refactor later when the number of cases grows.

     Erik


>
>
>
>> --- Ursprüngliche Nachricht ---
>> Von: Andreas Andreou <an...@di.uoa.gr>
>> An: Tapestry users <ta...@jakarta.apache.org>
>> Betreff: Re: Is that the way to do it ?
>> Datum: Thu, 09 Jun 2005 17:16:27 +0300
>>
>> Erik Hatcher wrote:
>>
>>
>>> I personally would not create this type of intermediate object just
>>> for the icon.  I'd map the 0/1 value to an asset in the page (or
>>> component) where it's needed.  Or perhaps in Global if its needed in
>>> lots of places.
>>>
>>
>>
>> I'd have to agree on that. Just define 2 assets in a page or  
>> component,
>> such as
>>   <context-asset name="gender0" path="images/male.gif"/>
>>   <context-asset name="gender1" path="images/female.gif"/>
>> and in the html use the image component with
>> image="ongl:assets['gender' + user.gender]"
>>
>>
>>>
>>>
>>>     Erik
>>>
>>>
>>> On Jun 9, 2005, at 4:07 AM, sarah.simbad@women-at-work.org wrote:
>>>
>>>
>>>> Hello everyone!
>>>>
>>>> My User class has a field called gender which is 0 or 1 for male or
>>>> female.
>>>> In order to display it as an Icon for "male" or "female" I am using
>>>>
>> the
>>
>>>> following approach and i wonder whether that is good practise and
>>>> thread-safe etc...
>>>>
>>>> My hibernate class is called HibernateUser
>>>>
>>>> I have an additional class called User which looks like that:
>>>>
>>>>
>>>> class User {
>>>>
>>>> private int gender;
>>>> private HibernateUser hibernateUser;
>>>>
>>>> public User (HibernateUser hibernateUser){
>>>> this.hibernateUser=hibernateUser;
>>>> }
>>>>
>>>> public String getIcon(){
>>>> if (gender.equals(0)){
>>>> return "male.gif";
>>>> }
>>>> else {
>>>> return "female.gif";
>>>> }
>>>>
>>>> }
>>>>
>>>> // + setter/getter for the private variables
>>>>
>>>> }
>>>>
>>>> Is that ok ?
>>>>
>>>> ------------------------------------------------------------------- 
>>>> --
>>>> To unsubscribe, e-mail: tapestry-user- 
>>>> unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail: tapestry-user- 
>>>> help@jakarta.apache.org
>>>>
>>>>
>>>
>>>
>>> -------------------------------------------------------------------- 
>>> -
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user- 
>>> help@jakarta.apache.org
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user- 
>> help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: Is that the way to do it ?

Posted by sa...@women-at-work.org.
Ok, I agree. For a simple image it is the way to do it.

But what, if it is some piece of html, that is generated from several
attributes from the User class ?

Something like:

<a href="some link">Firstname, Lastname, age </a>

Or would you create an extra component for that?


> --- Ursprüngliche Nachricht ---
> Von: Andreas Andreou <an...@di.uoa.gr>
> An: Tapestry users <ta...@jakarta.apache.org>
> Betreff: Re: Is that the way to do it ?
> Datum: Thu, 09 Jun 2005 17:16:27 +0300
> 
> Erik Hatcher wrote:
> 
> > I personally would not create this type of intermediate object just  
> > for the icon.  I'd map the 0/1 value to an asset in the page (or  
> > component) where it's needed.  Or perhaps in Global if its needed in  
> > lots of places.
> 
> 
> I'd have to agree on that. Just define 2 assets in a page or component, 
> such as
>   <context-asset name="gender0" path="images/male.gif"/>
>   <context-asset name="gender1" path="images/female.gif"/>
> and in the html use the image component with
> image="ongl:assets['gender' + user.gender]"
> 
> >
> >
> >     Erik
> >
> >
> > On Jun 9, 2005, at 4:07 AM, sarah.simbad@women-at-work.org wrote:
> >
> >> Hello everyone!
> >>
> >> My User class has a field called gender which is 0 or 1 for male or  
> >> female.
> >> In order to display it as an Icon for "male" or "female" I am using 
> the
> >> following approach and i wonder whether that is good practise and
> >> thread-safe etc...
> >>
> >> My hibernate class is called HibernateUser
> >>
> >> I have an additional class called User which looks like that:
> >>
> >>
> >> class User {
> >>
> >> private int gender;
> >> private HibernateUser hibernateUser;
> >>
> >> public User (HibernateUser hibernateUser){
> >> this.hibernateUser=hibernateUser;
> >> }
> >>
> >> public String getIcon(){
> >> if (gender.equals(0)){
> >> return "male.gif";
> >> }
> >> else {
> >> return "female.gif";
> >> }
> >>
> >> }
> >>
> >> // + setter/getter for the private variables
> >>
> >> }
> >>
> >> Is that ok ?
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 

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


Re: Is that the way to do it ?

Posted by Andreas Andreou <an...@di.uoa.gr>.
Erik Hatcher wrote:

> I personally would not create this type of intermediate object just  
> for the icon.  I'd map the 0/1 value to an asset in the page (or  
> component) where it's needed.  Or perhaps in Global if its needed in  
> lots of places.


I'd have to agree on that. Just define 2 assets in a page or component, 
such as
  <context-asset name="gender0" path="images/male.gif"/>
  <context-asset name="gender1" path="images/female.gif"/>
and in the html use the image component with
image="ongl:assets['gender' + user.gender]"

>
>
>     Erik
>
>
> On Jun 9, 2005, at 4:07 AM, sarah.simbad@women-at-work.org wrote:
>
>> Hello everyone!
>>
>> My User class has a field called gender which is 0 or 1 for male or  
>> female.
>> In order to display it as an Icon for "male" or "female" I am using  the
>> following approach and i wonder whether that is good practise and
>> thread-safe etc...
>>
>> My hibernate class is called HibernateUser
>>
>> I have an additional class called User which looks like that:
>>
>>
>> class User {
>>
>> private int gender;
>> private HibernateUser hibernateUser;
>>
>> public User (HibernateUser hibernateUser){
>> this.hibernateUser=hibernateUser;
>> }
>>
>> public String getIcon(){
>> if (gender.equals(0)){
>> return "male.gif";
>> }
>> else {
>> return "female.gif";
>> }
>>
>> }
>>
>> // + setter/getter for the private variables
>>
>> }
>>
>> Is that ok ?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


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


Re: Is that the way to do it ?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
I personally would not create this type of intermediate object just  
for the icon.  I'd map the 0/1 value to an asset in the page (or  
component) where it's needed.  Or perhaps in Global if its needed in  
lots of places.

     Erik


On Jun 9, 2005, at 4:07 AM, sarah.simbad@women-at-work.org wrote:

> Hello everyone!
>
> My User class has a field called gender which is 0 or 1 for male or  
> female.
> In order to display it as an Icon for "male" or "female" I am using  
> the
> following approach and i wonder whether that is good practise and
> thread-safe etc...
>
> My hibernate class is called HibernateUser
>
> I have an additional class called User which looks like that:
>
>
> class User {
>
> private int gender;
> private HibernateUser hibernateUser;
>
> public User (HibernateUser hibernateUser){
> this.hibernateUser=hibernateUser;
> }
>
> public String getIcon(){
> if (gender.equals(0)){
> return "male.gif";
> }
> else {
> return "female.gif";
> }
>
> }
>
> // + setter/getter for the private variables
>
> }
>
> Is that ok ?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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