What's now happening is that the validation correctly moves me back to the
jsp specified by input but the form becomes blank (doesn't keep the
information that was entered) and the <html:errors> returns nothing.

I can sort of get around this by calling validate and adding attributes to
the request but I'm pretty sure that I shouldn't need to do so. So I'm
wondering what's going wrong.

struts-config.xml:

<?xml version = '1.0' encoding = 'windows-1252'?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
Configuration 1.3.5//EN" "
http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd";>
<struts-config>
 <form-beans>
   <form-bean name="donorBean" type="
com.softrek.donation.AllDonationInformationFormBean3"/>
 </form-beans>
 <action-mappings>
   <action path="/donation3"   type="com.softrek.donation.DonationAction3"
           name="donorBean" scope="session"
           input="/donation3.jsp" validate="true">
     <forward name="error"  path="/error3.jsp"/>
     <forward name="success"      path="/thankYou3.jsp"/>
     <forward name="firstPage"    path="/donation3.jsp"/>
     <forward name="secondPage"   path="/honoree3.jsp"/>
     <forward name="thirdPage"    path="/payment3.jsp"/>
   </action>
 </action-mappings>
 <message-resources parameter="/WEB-INF/ErrorMessages"/>
 <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
   <set-property property="pathnames"
     value="/WEB-INF/validator/validator-rules.xml
,/WEB-INF/validator/validations.xml"/>
 </plug-in>

</struts-config>

public class AllDonationInformationFormBean3 extends ValidatorForm {
...
 // This is the addition I seem to need.
 public ActionErrors validate(ActionMapping mapping, HttpServletRequest
request) {
     ActionErrors actionErrors = super.validate(mapping, request) ;
     request.setAttribute("sessionForm", this) ; // If I don't do this the
form will be blank after an error.
     request.setAttribute("errors", actionErrors) ;
     return actionErrors ;
 }
}

My validations.xml file - working partially
<?xml version='1.0' encoding='windows-1252'?>
<form-validation>
 <formset>
   <!-- Start of validation rules for each bean -->
   <form name="donorBean">
     <field property="firstname" depends="required">
        <arg0 key="validation.error.firstname"/>
      </field>
     <field property="zip" depends="required">
        <arg0 key="validation.error.zip"/>
      </field>
      <field property="last" depends="required" page="1">
        <arg0 key="validation.error.last"/>
      </field>
      <field property="line1" depends="required" page="1">
        <arg0 key="validation.error.line1"/>
      </field>
      <field property="email" depends="email" page="1">
        <arg0 key="validation.error.email"/>
      </field>
      <field property="t_amount" depends="required" page="1">
        <arg0 key="validation.error.amount"/>
      </field>
      <field property="cc_number" depends="required, creditCard" page="1">
        <arg0 key="validation.error.ccnumber"/>
      </field>
    <!-- End of validation rules for each bean -->
   </form>
 </formset>
</form-validation>

Part of my jsp: only the getAttribute type of error shows up. the
<html:errors parts are empty.
I'd like to have them work so I can dump the getAttribute("errors") part.

   <form action="../donation3/donation3.do" method="post">
     <input type="hidden" name="pagename" value="donationPage"/>
     <p style="background-color:rgb(0,255,255); font-size:large;">Donor
Information</p>
     All errors with Java script
     <%= request.getAttribute("errors") == null ? "No errors" :
request.getAttribute("errors") %><br/>
     All errors with strut tag
     <html:errors/><br/>
     Single error report with strut tag
     <html:errors property="firstname"/>
     <p>*Indicates required field</p>
     <p>


On 11/7/06, Romu <[EMAIL PROTECTED]> wrote:

validations are linked to xml files:

<action
            path="/XXX"
            name="yourForm"
            scope="session"
            validate="false"
             type="yyyAction">
            <forward name="succees" path="/WEB-INF/jsp/success.jsp"/>

        </action>

with name tag, struts will look in validation.xml files to see the rules
etc
, and it wil generates the javascript .

check if u got javascript validation code  in your jsp  ?





2006/11/7, Thom Burnett <[EMAIL PROTECTED]>:
>
> What are common simple mistakes that would prevent validation from
> occuring?
> I've got a simple struts application that runs correctly except that
> validation doesn't occur. The form info is accepted as correct when
> required
> information is missing.
>
> I'm trying to figure out what's missing from my setup or understanding.
>
> The ValidatorForm (my extension) class has appropriate get and set
> functions
> for all fields.
> (The fields are spread over 3 jsp pages, if that matters.)
> I've added the validator plugin to the struts-config, the action mapping
> has
> validate="true" and a valid input path,  added the validation-rules and
> validation.xml file, added the resource properties file with the
standard
> errors (taken from the struts file).
>
> If I write my own validate method in the form bean that validation works
> properly. It's my understanding that if I'm using the validation
> framework,
> I should not have a validate() method in the form.
>
> Am I misunderstanding something? Any ideas what might be setup wrong or
> missing.
>
>


Reply via email to