• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

bean (type date) and the problem with jsp

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

Empl

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:
Empl

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
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sure there are plenty of threads that touch on this topic. Here is one recent one that I remember:

https://coderanch.com/t/54892/Struts/Struts-transform-httpRequest-Java-Objects

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
reply
    Bookmark Topic Watch Topic
  • New Topic