You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by maestro <ma...@gmail.com> on 2009/09/29 19:06:41 UTC

S2: Validation not happening

I have searched and compared to no avail.
This one has been stumping me for some time now.
I'm trying to use the validation.xml. I have it working on one page and not
on the other.

Perhaps you can spot the error?

struts.xml

    <package name="crm" extends="struts-default">

        <action name="customer.update" method="update"
class="ca.pan.crm.customer.UpdateAction">
            <result name="add">/WEB-INF/customer/update.jsp</result>
            <result name="cancel"
type="redirectAction">customer.list</result>
            <result name="input">/WEB-INF/customer/update.jsp</result>
            <result name="success"
type="redirectAction">customer.list</result>
        </action>

    </package>


public class UpdateAction extends ActionSupport
    implements ModelDriven<Customer>, Preparable, SessionAware {

    public String update() throws Exception {

        return SUCCESS;
    }



UpdateAction-customer.update-validation.xml

<validators>
  <field name="companyName">
      <field-validator type="requiredstring">
           <message >${getText("msg.companyName.required")}</message>
      </field-validator>
      <field-validator type="stringlength">
         <param name="maxLength">255</param>
         <param name="minLength">1</param>
         <message>${getText("msg.companyName.invalid.length")}</message>
     </field-validator>
  </field>
</validators>


JSP
<s:form action="customer.update.action" method="post" validate="true"
name="frmPost">
...
                <tr>
                    <td></td>
                    <td class="manditoryStar">*</td>
                    <td><s:text name="customer.field.company.name"/><s:text
name="text.colon"/></td>
                    <td><s:textfield name="companyName" size="60"
maxlength="255"/></td>
                    <td></td>
                </tr>


The only difference between the one that works and this one that doesn't is
the fields referenced in validation xml are defined in the Action class
whereas the ones in the example that doesn't work are defined in the
Customer class.

So I tried the validation.xml as follows without any success either.
  <field name="customer.companyName">

Gimme anything you can think of!!!

Re: S2: Validation not happening

Posted by maestro <ma...@gmail.com>.
For sake of completeness, I have decided to drop the Validation.xml route
and go with the plain old java validation. Time is running, and so am I. :)

On Tue, Sep 29, 2009 at 1:06 PM, maestro <ma...@gmail.com> wrote:

> I have searched and compared to no avail.
> This one has been stumping me for some time now.
> I'm trying to use the validation.xml. I have it working on one page and not
> on the other.
>
> Perhaps you can spot the error?
>
> struts.xml
>
>     <package name="crm" extends="struts-default">
>
>         <action name="customer.update" method="update"
> class="ca.pan.crm.customer.UpdateAction">
>             <result name="add">/WEB-INF/customer/update.jsp</result>
>             <result name="cancel"
> type="redirectAction">customer.list</result>
>             <result name="input">/WEB-INF/customer/update.jsp</result>
>             <result name="success"
> type="redirectAction">customer.list</result>
>         </action>
>
>     </package>
>
>
> public class UpdateAction extends ActionSupport
>     implements ModelDriven<Customer>, Preparable, SessionAware {
>
>     public String update() throws Exception {
>
>         return SUCCESS;
>     }
>
>
>
> UpdateAction-customer.update-validation.xml
>
> <validators>
>   <field name="companyName">
>       <field-validator type="requiredstring">
>            <message >${getText("msg.companyName.required")}</message>
>       </field-validator>
>       <field-validator type="stringlength">
>          <param name="maxLength">255</param>
>          <param name="minLength">1</param>
>          <message>${getText("msg.companyName.invalid.length")}</message>
>      </field-validator>
>   </field>
> </validators>
>
>
> JSP
> <s:form action="customer.update.action" method="post" validate="true"
> name="frmPost">
> ...
>                 <tr>
>                     <td></td>
>                     <td class="manditoryStar">*</td>
>                     <td><s:text name="customer.field.company.name"/><s:text
> name="text.colon"/></td>
>                     <td><s:textfield name="companyName" size="60"
> maxlength="255"/></td>
>                     <td></td>
>                 </tr>
>
>
> The only difference between the one that works and this one that doesn't is
> the fields referenced in validation xml are defined in the Action class
> whereas the ones in the example that doesn't work are defined in the
> Customer class.
>
> So I tried the validation.xml as follows without any success either.
>   <field name="customer.companyName">
>
> Gimme anything you can think of!!!
>
>