This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Problems with date validation in Struts 1.2.4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problems with date validation in Struts 1.2.4" Watch "Problems with date validation in Struts 1.2.4" New topic
Author

Problems with date validation in Struts 1.2.4

Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
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

Joined: Feb 05, 2003
Posts: 4727

Shouldn't the form name in validation.xml be inquiryForm?


A good workman is known by his tools.
Kinjal Sonpal
Ranch Hand

Joined: Jun 06, 2003
Posts: 96
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

Joined: Jun 06, 2003
Posts: 96
Aloha .. Anyone with ideas?
Trevor Whitehead
Greenhorn

Joined: Oct 16, 2002
Posts: 16
are any of the form elements validating?
Trevor Whitehead
Greenhorn

Joined: Oct 16, 2002
Posts: 16
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

Joined: Feb 05, 2003
Posts: 4727

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with date validation in Struts 1.2.4
 
Similar Threads
Problems with Indexed Properties - Repost
Struts 1.2.4 File Upload - Form File is null in action
Date Validator scrolls the date
can somebody take a look at my struts--config file?
Html:link forward +parameter passing