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

STRUTS VALIDATOR - is it a myth?

 
Jason Kosowan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 314
2
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go thru this chapter, you should get answers to all your questions.
http://www.bkbear.com/Chapter17.pdf
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic