struts 2 validation.xml not validating.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NamelessNumberheadMan
    New Member
    • Jul 2007
    • 15

    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?
    UserFileLoadAct ion-validation.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
           "[URL]http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd[/URL]">
    <validators>
     <field name="typeId">
      <field-validator type="int">
       <param name="min">1</param>
       <message>Message</message>
      </field-validator>
     </field>
     <field name="month">
      <field-validator type="int">
       <param name="min">1</param>
       <message>Message</message>
      </field-validator>
     </field>
     <field name="year">
      <field-validator type="int">
       <param name="min">1988</param>
       <message>Message</message>
      </field-validator>
     </field>
     <field name="inputFile">
      <field-validator type="required">
       <message>Message</message>
      </field-validator>
     </field>
    </validators>
    struts.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "[URL]http://struts.apache.org/dtds/struts-2.0.dtd[/URL]">
    <struts>
     <package name="loadFile" namespace="/secure"
      extends="struts-default">
      <result-types>
       <result-type name="tiles"
        class="org.apache.struts2.views.tiles.TilesResult" />
      </result-types>
      <action name="loadFile">
       <result type="tiles">.user.LoadFile</result>
      </action>
      <action name="LoadUserFile"
       class="com.organization.struts.user.UserFileLoadAction">
       <interceptor-ref name="paramsPrepareParamsStack" />
       <interceptor-ref name="defaultStack" />
       <interceptor-ref name="validation">
        <param name="excludeMethods">
         input,back,cancel,browse
        </param>
       </interceptor-ref>
       <interceptor-ref name="roles">
        <param name="allowedRoles">UserFile-Upload</param>
       </interceptor-ref>
       <result name="success" type="tiles">
        .user.loadSuccessful
       </result>
       <result name="cancel" type="tiles">/secure/home.do</result>
       <result name="error" type="tiles">.user.LoadFile</result>
      </action>
     </package>
    </struts>
  • sau tiwari

    #2
    For default implementation of validation you must have at least one result with name error/input.

    Comment

    Working...