File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes STRUTS VALIDATOR - is it a myth? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "STRUTS VALIDATOR - is it a myth?" Watch "STRUTS VALIDATOR - is it a myth?" New topic

STRUTS VALIDATOR - is it a myth?

Jason Kosowan

Joined: Sep 25, 2001
Posts: 9
I can't believe how much problem I've been having with the struts validator framework! I can get NOTHING to work and have spent HOURS on this! I've read about 4 online tutorials, went through 3 textbooks and it's still not working.
Any help would be appreciated. Here is my DIRT SIMPLE example that DOESN'T work.... Grrrrrr....
-- struts-config.xml --
<form-bean name="TestForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="email" type="java.lang.String"/>
<action path="/TestAction"
<forward name="GOOD" path="/thankyou.jsp"/>

-- validation.xml --
<form name="TestForm">
<field-property name="email" depends="required"/>
-- my test.jsp --
<%@ include file="/WEB-INF/taglibs.jsp" %>
<H1>test page</H1>
Errors start
Errors end
<html:form action="/TestAction">
Your email: <html:text property="email"/><P>
Note: the WEB-INF/taglibs.jsp contains taglib declarations for all struts taglibs. (This is the ONE thing that actually works in this project of mine). Also the action class does nothing but return the "GOOD" string. (It SHOULDN'T do anything, right? The validation framework is automatic, right?)
So, I boot my server and ensure that both validation XMLs are loaded. Then go into my input page, just push the submit without filling in the email section to test the validation. I am immediately ushered to the "Thank you for the valid data" screen.
What is wrong here? I've seen about 8 posts via google about people having problems with this, but not one answer. I'm to the point where I now believe that the validation framework is vaporware!
[ July 13, 2003: Message edited by: Jason Kosowan ]
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi there,
My suggestion might be in left field because I haven't used the Validator Framework for a LONG time and my books aren't not here. But I seem to recall that when using DynaValidatorForms, you need to associate the action with validation codem not the form bean per se. Try changing the validation code to refer to the name of the Struts action instead of the form bean.
Here is an example from my code. If I have a form bean defined as follows:

and if I have an action defined as follows:

then validation code could look like:

I hope this helps.
Darryl A. J. Staflund
Ranch Hand

Joined: Oct 06, 2002
Posts: 303
Hi again,
And of course, don't forget to register the validator plugin in the struts-config.xml file as follows:

Jason Kosowan

Joined: Sep 25, 2001
Posts: 9
Hi again and thanks for the suggestions. I tried the suggestion about putting the action into the validation.xml, however and still no luck. So, then I went even simpler. I switched to a normal validator form to test even if the regular Validation worked. I made sure to extend from ValidatorForm and put in all of the niceties but *No Dice*. I'm completely stumped.

It must be something small that I'm missing here. I'd love to be able to use this framework and thought it would be fairly straightforward, but the integration is astoundingly rough.
If anyone has more ideas, please let me know.
I think my next step is to override the validate in the ValidatorForm and see if it even gets called. If it doesn't then I think I've got a very bad problem.
Maybe it's my container? (I'm running Resin 2.19)
Jason Kosowan

Joined: Sep 25, 2001
Posts: 9
More news - overriding the validation portion of the form confirms that the validation is being automatically called.
But, it also confirms that the super.validate is not returning any ActionErrors, regardless of invalid input!
Sreedhar Busanelli

Joined: Jul 17, 2003
Posts: 3
Go thru this chapter, you should get answers to all your questions.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: STRUTS VALIDATOR - is it a myth?
It's not a secret anymore!