471,337 Members | 985 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

struts 2 validation.xml not validating.

I can't seem to get Struts 2 validations to work. I have been converting from Strust 1 to Struts 2. So far I've refactored all the code (for this particular module) on the back end, rewrote the jsp using Struts 2 notations, and wired up the xml (aside from the abc-validation.xml). Everything runs just fine. If there is an error not generated by user input (i.e. file format problem) I can get that message to come out, so I know my error messages work. I try to add the abc-validation.xml for my abc class, but the validations never catch. The input field types I'm using are of select (x3) and file(x1). The selects all use numbers (default 0), and the file is just a file path (default blank). I set my validation.xml (below) to have a min of 1 for the selects, and required for the file field. So when I hit submit I expect something to come back with out hitting my action class, but it doesn't. My action does extend ActionSupport and implements RequestAware. Can anyone point me in the right direction?
UserFileLoadAction-validation.xml:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
  3.        "http://www.opensymphony.com/xwork/xw...ator-1.0.2.dtd">
  4. <validators>
  5.  <field name="typeId">
  6.   <field-validator type="int">
  7.    <param name="min">1</param>
  8.    <message>Message</message>
  9.   </field-validator>
  10.  </field>
  11.  <field name="month">
  12.   <field-validator type="int">
  13.    <param name="min">1</param>
  14.    <message>Message</message>
  15.   </field-validator>
  16.  </field>
  17.  <field name="year">
  18.   <field-validator type="int">
  19.    <param name="min">1988</param>
  20.    <message>Message</message>
  21.   </field-validator>
  22.  </field>
  23.  <field name="inputFile">
  24.   <field-validator type="required">
  25.    <message>Message</message>
  26.   </field-validator>
  27.  </field>
  28. </validators>
  29.  
struts.xml:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE struts PUBLIC
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">
  5. <struts>
  6.  <package name="loadFile" namespace="/secure"
  7.   extends="struts-default">
  8.   <result-types>
  9.    <result-type name="tiles"
  10.     class="org.apache.struts2.views.tiles.TilesResult" />
  11.   </result-types>
  12.   <action name="loadFile">
  13.    <result type="tiles">.user.LoadFile</result>
  14.   </action>
  15.   <action name="LoadUserFile"
  16.    class="com.organization.struts.user.UserFileLoadAction">
  17.    <interceptor-ref name="paramsPrepareParamsStack" />
  18.    <interceptor-ref name="defaultStack" />
  19.    <interceptor-ref name="validation">
  20.     <param name="excludeMethods">
  21.      input,back,cancel,browse
  22.     </param>
  23.    </interceptor-ref>
  24.    <interceptor-ref name="roles">
  25.     <param name="allowedRoles">UserFile-Upload</param>
  26.    </interceptor-ref>
  27.    <result name="success" type="tiles">
  28.     .user.loadSuccessful
  29.    </result>
  30.    <result name="cancel" type="tiles">/secure/home.do</result>
  31.    <result name="error" type="tiles">.user.LoadFile</result>
  32.   </action>
  33.  </package>
  34. </struts>
  35.  
Jan 21 '09 #1
1 11261
For default implementation of validation you must have at least one result with name error/input.
Oct 25 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Alex M | last post: by
2 posts views Thread by Tim Frawley | last post: by
5 posts views Thread by Micky | last post: by
1 post views Thread by nithiya sri | last post: by
8 posts views Thread by ajos | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.