Tom Bednarz wrote:
I think the validator fires too early, but probably I am doing something wrong. Maybe somebody can hp!

Basically, you need 2 actions, one to populate the form and one to change the personal data.




I have the following form bean defined in struts-config.xml:

<form-bean name="changePersonalDataForm" type="org.apache.struts.validator.DynaValidatorActionForm" >
        <form-property name="subscriberid" type="java.lang.String" />
        <form-property name="firstname" type="java.lang.String" />
        <form-property name="familyname" type="java.lang.String" />
        <form-property name="zip" type="java.lang.String" />
        <form-property name="place" type="java.lang.String" />
        <form-property name="country" type="java.lang.String" />
        <form-property name="addr1" type="java.lang.String" />
        <form-property name="addr2" type="java.lang.String" />
        <form-property name="addr3" type="java.lang.String" />
        <form-property name="email" type="java.lang.String" />
    </form-bean>


and the following action mapping:

    <action
      attribute="changePersonalDataForm"
      input="/form/changePersonalData.jsp"
      name="changePersonalDataForm"
      path="/changePersonalData"
      scope="request"
      type="ch.smartsol.struts.action.ChangePersonalDataAction">
      <forward name="success" path="/template/SuccessMessage.jsp" />
      <forward name="failure" path="/form/changePersonalData.jsp" />
    </action>


The idea is, that I show a form that contains already data and the user can edit it. When the form is submitted, the validator should check the user input. Here is my validator configuration:


<form name="/changePersonalData">
  <field property="firstname" depends="required">
    <msg name="required" key="PersonalData.firstname.required"/>
  </field>
  <field property="familyname" depends="required">
    <msg name="required" key="PersonalData.familyname.required"/>
  </field>
  <field property="zip" depends="required">
    <msg name="required" key="PersonalData.zip.required"/>
  </field>
  <field property="place" depends="required">
    <msg name="required" key="PersonalData.place.required"/>
  </field>
  <field property="country" depends="required">
    <msg name="required" key="PersonalData.country.required"/>
  </field>
  <field property="addr1" depends="required">
    <msg name="required" key="PersonalData.addr1.required"/>
  </field>
  <field property="email" depends="required,email">
    <msg name="required" key="PersonalData.email.required"/>
    <msg name="email" key="PersonalData.email.email"/>
  </field>
</form>

Now it seems, that the validator gets fired BEFORE the form is filled! In the JSP that displays the form, I get lots of error messages all fired by the 'required' validator saying, that the field must not be empty, but all fields are filled corretly!!.

Here is an extract of the JSP:

<TABLE border="0" width="95%" align="center">
  <TR>
    <TD class="headerLeftLight" width="200">
       <bean:message key="ChangePersonalData.firstname"/>
    </TD>
    <TD class="dataLightAlignLeft" width="200">
      <html:text value="${sessionScope.subscriber.firstname}"
      property="firstname" name="firstname" maxlength="64"
      size="32"/>
    </TD>
    <TD class="errMessage">
       <html:errors property="firstname"/>
    </TD>
  </TR>
  <TR>
    <TD class="headerLeftStrong">
      <bean:message key="ChangePersonalData.lastname"/>
    </TD>
    <TD class="dataStrongAlignLeft">
      <html:text value="${sessionScope.subscriber.familyname}"
      property="familyname" name="familyname" maxlength="64"
      size="32"/>
    </TD>
    <TD class="errMessage">
      <html:errors property="familyname"/>
    </TD>
  </TR>
  .......

 </TABLE>

Every row contains a label, an input control and a TD to display validation errors of the specific field.

Does anybody know what is going wrong here??

Many thanks for your help!

Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to