You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Laurie Harper <zo...@holoweb.net> on 2004/04/01 03:06:30 UTC

validaton and i18n

I've finally managed to get the Struts Validator working, thanks to the 
sample chapter on it from Struts in Action. I'm having one small problem 
still, though. When validation fails, I get a blank alery popup.

Looking at the generated Javascript the problem appears to be that the 
message strings aren't populated:

     function required () {
      this.aa = new Array("email", "", new Function ("varName", 
"this.mask=/^([!#\\$%&'\\*\\+\\-\\.\\/0-9=\\?A-Z\\^\\x5E_`a-z\\{\\|\\}~]+)@(([0-9a-zA-Z]([0-9a-zA-Z-]*[0-9a-zA-Z])?)(\\.[0-9a-zA-Z]([0-9a-zA-Z-]*[0-9a-zA-Z])?)+)$/; 
  return this[varName];"));
      this.ab = new Array("password", "", new Function ("varName", " 
return this[varName];"));
     }

The message keys are defined in the validation.xml file, I think correctly:

     <formset>
         <form name="logonForm">
             <field property="email" depends="required,mask">
                 <arg0 key="logon.error.email.missing"/>
                 <var>
                     <var-name>mask</var-name>
 
<var-value>^([!#\$%&amp;'\*\+\-\.\/0-9=\?A-Z\^\x5E_`a-z\{\|\}~]+)@(([0-9a-zA-Z]([0-9a-zA-Z-]*[0-9a-zA-Z])?)(\.[0-9a-zA-Z]([0-9a-zA-Z-]*[0-9a-zA-Z])?)+)$</var-value>
                 </var>
             </field>
             <field property="password" depends="required">
                 <arg0 key="logon.error.password.missing"/>
             </field>
         </form>
     </formset>

The message resources are defined and, indeed, I can see in the Struts 
debug log that they're being looked up when the form is rendered:

L4J 2004-03-31 19:52:00,945 DEBUG PropertyMessageResources 
getMessage(en_US,errors.required)

L4J 2004-03-31 19:52:00,946 DEBUG PropertyMessageResources 
getMessage(en_US,logon.error.password.missing)
L4J 2004-03-31 19:52:00,946 DEBUG PropertyMessageResources loadLocale(en_US)
L4J 2004-03-31 19:52:00,946 DEBUG PropertyMessageResources 
getMessage(en_US,errors.required)
L4J 2004-03-31 19:52:00,957 DEBUG PropertyMessageResources 
getMessage(en_US,logon.error.email.missing)

They just never get pushed to the page. Here's what I'm using to get the 
form validation in my JSP:

   <html:form action="/logon" focus="email"
       onsubmit="return validateLogonForm(this)">
     <html:javascript formName="logonForm"/>
     ...

What have I missed?

Thanks,

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org