• 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

[Struts] Various questions

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Development Enviroment:
Struts, Hibernate (MyEclipse), Oracle 9i, Tomcat 5.0.28

Question 1:
I have a jsp page with a form on it, that contains a date text field:


This attribute comes from a colum in a database table, automatically mapped by Hibernate into a persistent class where it's declared as public Date geboortedatum with its proper getter and setter.

When I submit I get the bean Populate, mismatched argument type, Native Method exception:


When I remove the text field and submit, all goes well inserting a NULL value in the geboortedatum table column, but when the text field is on the page and I submit REGARDLESS of inserting a value or not in it, it gives me the error.

I'm guessing here it has something to do with date formatting/type but I don't know for sure. Something almost like parsing an int to a string kinda thing? I got other fields that are declared as longs and ints and that goes all well, no converting needed, cause it's all properly mapped in the hibernate xml file. So I'm not sure about this one.

Question 2:
About dropdown menu's in jsp w/ (struts)tags...
I've been eating my head off on this one. I only manage to get this text area kinda thing with the values in it (all shown) and being able to select multiple values in that list.
I just want a normal drop down list. So can someone please post a good working example for this (dynamic)? I can only find good javascript examples, but if possible I'd like to prevent using javascript for that.
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Within your form, geboortedatum should have get and set that operate on a String, not a Date (Struts is setting a String to the form and expects a String from the get). If you want to also work with a Date object for that variable, define further methods like getGeboortedatumDate.

for the drop-down, don't define multiple and you'll get a regular drop-down.
[ November 02, 2004: Message edited by: Ray Stojonic ]
 
Ritchie Warsi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tnx Ray, fixed the dropdown issue, small little mistake

About the date, it won't just work by changing the type to String.
Hibernate generates the persistent class according to the database tables, so it's set to Date (geboortedatum that is).
Even when I change Date everywhere to String it doesn't get inserted (errors again).

So to sum up the issue:
AbstractBelastingplichtige.java contains:

My formbean named BelastingplichtigeForm.java contains the exact same declaration and setters & getters.

My Action named AddBelastingplichtige.java contains:

And my JSP has the code as shown in my first post.

The date needs to be inserted in a Oracle database, that reads out (with a select from statement) as yyyy-MM-dd hh:mm:ss, but that's not an issue right now.

I don't really get that getGeboortedatumDate method. How do I implement that and will that "convert" my string value from the textfield to a date format?
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is what I had in mind:

then in jsp:
<html:text property='dateStr'/>

this allows your bean to go both ways: Date interactivity with the db and String interactivity with the jsp.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The getter and setter should both have a try/catch.

Other than that, looks good to me.
 
Ritchie Warsi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ray, tnx, i undstand your code (I'm a beginning struts developer) and I implemented it, but it gives me an error (I set a try/catch).

I got this in my formbean now (BelastingPlichtigeForm.java):


And my property in my JSP is now dateStr in stead of the previous geboortedatum (see first post)
As you can see also I just put a simple try/catch so I ain't got much of a stacktrace:

I don't know if this is related to the part in my Action (see my second post up here) where the geboortedatum property is gotten en set, so should this be changed to dateStr also. If I do that I get the error:
"The method setDateStr(Date) is undefined for the type Belastingplichtige.java" -> Generated java file for the table belastingplichtige which extends AbstractBelastingplichtige (see first post).

So what am I doin' wrong here?
 
Ritchie Warsi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone have any idea..?
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read my last post. It is the getter that has the exception according to the stack trace, right?
 
Ritchie Warsi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it does, i minunderstood you sorry.
I've tried to put a try/catch also with the getDateStr, but Eclipse warning me about something like exception not being thrown and to just remove the catch, so it gets back to what I have right now.

So can u tell me how to properly add a try/catch for the getter?
(I just know basic try/catch)
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the Action side, you need to operate with the Date object, which was the whole reason for all this.

DateFormat.format( java.util.Date ) doesn't throw anything, so there's nothing to catch.

In the log for this context there should be more information, my guess is that you're getting a NullPointerException.

in getDateStr, verify it's not null and return an empty string if it is.

Even better, figure out why it's not getting set.
[ November 04, 2004: Message edited by: Ray Stojonic ]
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to get a NullPointerException even though it is not specified as a throws in the SimpleDateFormat class's format method.

Perhaps the thing to do instead of try/catch is to perform a null check.
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dang, Ray beat me to the submission!
 
Ritchie Warsi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Ray, i wouldn't know why it isn't getting set, cuz i get the stacktrace when calling on the form.

The suggestion Marc gave worked perfectly and date gets inserted succesfully.
Tnx for your comments, maybe u don't know, but it helped me a lot with understanding more about it
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad it worked out for you.

For debugging, System.out.println works wonders, the output will come up on the Tomcat console, assuming you don't have it running as a service.
 
Ritchie Warsi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah i use it as a service, but Eclipse (MyEclipse) has the console in it too, so i see what u mean!

Only thing to figure out now is how to not show the date that hibernate retrieves from my oracle database without the time (yyyy-MM-dd and not yyyy-MM-dd hh:mm:s) grmbl..
 
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic