This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Struts and the fly likes bean (type date)  and the problem with jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean (type date)  and the problem with jsp " Watch "bean (type date)  and the problem with jsp " New topic

bean (type date) and the problem with jsp

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi guys,

I have this 'issue' and wonder if someone can tell me if my solution is ok (I'm not content with it)

the problem is with the bean I'm creating. example:


String fname;
Date dob;

// + getter and setter

as you can see, the DOB is type date, when using the jsp page, the code looks like this:

<html:text property="dob" />

well, I realized that this will throw an err:

Cannot invoke com.struts.domain.Emp.setDob - argument type mismatch

(JSP expects a String and I provided a Date)

my solution is this:

String fname;
Date dob;
String dobStr

(and then I replace everything in the jsp page)
this works BUT there's so much extra work and the amount of properties really gets big for no reason.

can anyone advise on a better solution (not with DynaValidatorForm)

thanks a lot
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I am sure there are plenty of threads that touch on this topic. Here is one recent one that I remember:

So what is your Empl object? If you have a multi-tiered system, what layer(s) use this object? You are right that Struts forms should us String values. If Empl is a business or data layer object, then I would probably create an ActionForm that had fname and dob fields as Strings. You would then have to write code that populated the form from the Empl object and populated an Empl object from the form. It is a little bit of a pain, but not too bad.

For read only pages (like search results pages) I have added methods like getFormattedDob() to data layer objects. In this case, iterating over a collection and translating each data object into a presentation object seems like too much overhead just to format a few fields.

- Brent
It is sorta covered in the JavaRanch Style Guide.
subject: bean (type date) and the problem with jsp
jQuery in Action, 3rd edition