File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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
I agree. Here's the link:
subject: bean (type date) and the problem with jsp
It's not a secret anymore!