Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with date validation in Struts 1.2.4

 
Kinjal Sonpal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I've been trying to get Dates validation for my Struts project without any success. I'm using struts 1.2.4 with Validator 1.1.3 on tomcat 5.0.27.

In my application, I'm having a hier of MappingDispatchAction for Action, where individual action mappings in struts-config map to individual method in the Action class. The form is a child of ValidatorActionForm with a VO bean for holding business data and a string for holding the value for the date field. The VO bean contains a java.sql.Date field. In the getter and setter of the textual field, I get and set the data from VO bean, so as to have virtually a String-only ActionForm.

I'm pasting relevant codes below
struts-config.xml:

validation.xml:

editDetail.jsp:


Now, everytime I submit the page and if the field is empty it throws me an exception related to beanUtils.populate(). According to my understanding this type of exception should only come when struts copying data into the ActionForm is problamatic. However, it seems to me that the validator is somehow bypassed.

If I remove the copying (to and from the VO bean into the textual date field) code from my ActionForm, it validates things properly.

I'm not sure what is going wrong here and hence I'm seeking the advise here. I've gone throgh all major mailing lists and forums for struts for any hints on this, but could find little. I'm sorry for such a long post, but I wanted include maximum data into the post.

Thanks and regards,
Kinjal Sonpal
[ November 02, 2004: Message edited by: Kinjal Sonpal ]
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shouldn't the form name in validation.xml be inquiryForm?
 
Kinjal Sonpal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marc,

Originally posted by Marc Peabody:
Shouldn't the form name in validation.xml be inquiryForm?
If the ActionForm is ValidatorActionForm, the form-name in validation.xml should be the Action path being submitted by the Jsp, rather than the form-bean instance name. It turns out to be a clean way of doing things when the Actions are subclasses of DispatchAction.

Thanks and regards,
Kinjal Sonpal
[ November 02, 2004: Message edited by: Kinjal Sonpal ]
 
Kinjal Sonpal
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aloha .. Anyone with ideas?
 
Trevor Whitehead
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are any of the form elements validating?
 
Trevor Whitehead
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marc Peabody:
Shouldn't the form name in validation.xml be inquiryForm?


I agree, the form name in validation.xml should be the same as the action name in the configurations file.
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kinjal is correct that ValidatorActionForm will use AcionMapping's path.

After reading the post more throroughly I think I see what is wrong. Struts will call the setters upon submission before it ever runs the validate method. It's not bypassing the validation, it just fails before it ever gets to the validation. By the way, if a textfield is left blank, it WILL call the setter with an empty String ("") parameter.

That's the problem with using picky objects in your ActionForm (such as Date). I usually try to keep my submissions as Strings and if it passes validation have my Action convert the data to the proper data types.

Sorry I was not much help earlier. Best of luck.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic