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 STRUTS VALIDATOR - is it a myth? 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 "STRUTS VALIDATOR - is it a myth?" Watch "STRUTS VALIDATOR - is it a myth?" New topic
Author

STRUTS VALIDATOR - is it a myth?

Jason Kosowan
Greenhorn

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"/>
</form-bean>
.
.
.
<action path="/TestAction"
type="mypack.TestAction"
name="TestForm"
input="/test.jsp">
<forward name="GOOD" path="/thankyou.jsp"/>
</action>

-- validation.xml --
<form name="TestForm">
<field-property name="email" depends="required"/>
</form>
-- my test.jsp --
<%@ include file="/WEB-INF/taglibs.jsp" %>
<HTML><HEAD><TITLE>Test page</TITLE></HEAD>
<BODY>
<H1>test page</H1>
<P>
Errors start
<BR>
<html:errors/>
Errors end
<P>
<html:form action="/TestAction">
Your email: <html:text property="email"/><P>
<html:submit/>
</html:form>
</BODY></HTML>
*************************
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
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:

Cheers,
Darryl
Jason Kosowan
Greenhorn

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
Greenhorn

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
Greenhorn

Joined: Jul 17, 2003
Posts: 3
Go thru this chapter, you should get answers to all your questions.
http://www.bkbear.com/Chapter17.pdf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: STRUTS VALIDATOR - is it a myth?
 
Similar Threads
html optionsCollection Faild to obtain Collection
help with validation framework
Struts Validator Configuration
Struts Validator Framework
form values not showing in jsp