You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/03/28 07:17:41 UTC

Displaying non-String properties of beans

I'm sure this question has come up but I'm not having much luck search
the archives. I'm really new to Struts so I hope this question isn't
too out of place for this list. Lets see we are dealing with Employee
beans.
I like to have my EmployeeBean maintain the datatypes of the members
to not have to all be Strings. (In this example say Age would be an
int, birthDate a java.util.Date, etc.). Now in my sample app I'm
practicing with I have an EmployeeForm class also that currently has
just String datatypes for these fields.  Having the information from
the actual form jsp's going to the EmployeeForm in as all Strings
without any conversions is not that big of a deal since wherever I do
anything with this data (jdbc inserts in the business logic I could
always covert them there if I need to ). However, I'm more concerned
with getting this information out and to display using the tags. For
example, say I have on an Action class that gets back and ArrayList of
EmployeeBean objects and puts this list into the request before
forwarding. I assume I can't do:

<logic:iterate id="row" name="employeeList">
    <bean:write name="row" property="firstName"/><BR>
    <bean:write name="row" property="lastName"/><BR>
    <bean:write name="row" property="age"/><BR>
    <bean:write name="row" property="birthDate"/><BR>
    <BR>
</logic:iterate>

since I won't have birthDate formatted correctly, or say I was
returning a Double that I needed in a currency format. What is the
best way to deal with this situation?  I could of course maybe have my
business logic return me a Collection of EmployeeForm beans instead
and inside the EmployeeForm beans there would be methods like
setBirthDateDate( Date date ) that would take a java.util.Date and format it into
a String and then call the EmployeeForm setBrithDate( String date ).
Although that would work, I'd still rather deal with the business
logic that returns a Collection of EmployeeBeans... as this seems to
make the most reusable sense (maybe the components later won't just be
for the web).

Thanks for any help.

--

Rick

mailto:maillist@reumann.net

"Marta was watching the football game with me when she said, 'You
know, most of these sports are based on the idea of one group
protecting its territory from invasion by another group.' 'Yeah,' I
said, trying not to laugh. Girls are funny."
  -Jack Handey


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>