| Author |
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: 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
|
 |
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: http://www.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
|
 |
 |
|
|
subject: bean (type date) and the problem with jsp
|
|
|