You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeroen Breedveld <je...@x-hive.com> on 2003/10/03 10:25:40 UTC

Simple validator question

Hi all,

Is it possible to supply the msg element with the value the user entered
in the form as the content of the arg element? 

My key errors.login.email.invalid is: {0} is an invalid email address
So when a user enters 'foo' as an email adres I want an error message
saying: 'foo is an invalid email address'

Is this possible? Here is the code:

    <form name="MailPasswordForm">
      <field property="email" depends="required,email">
        <msg name="required" key="errors.login.email.required"/>
        <msg name="email" key="errors.login.email.invalid"/>
        <arg0 name="email" key="email"/>
      </field>
    </form>

Thanks and regards,

Jeroen

--

X-Hive Corporation
e-mail: jeroenb@x-hive.com
phone: +31 10 2818080
http://www.x-hive.com 

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


RE: Simple validator question

Posted by Jeroen Breedveld <je...@x-hive.com>.
Hi Jeff,

 || -----Original Message-----
 || From: Jeff Kyser [mailto:ktrails@comcast.net] 
 || Sent: vrijdag 3 oktober 2003 14:24
 || To: Struts Users Mailing List
 || Subject: Re: Simple validator question
 || 

...

 ||              <field property="emailField" depends="email" >
 ||                  <arg0 key="validateForm.emailField.errorname"/>
 ||              </field>
 || 
 || other pertinent entries (for the code above) in the 
 || ApplicationResources.properties file:
 || 
 || 	validateForm.emailField.errorname=Foo

Thanks for your help but this is not what I meant. I've probably not
been clear enough. I do not want the string 'foo' to come from a
resource file but it has to be what the user entered in the html:text
input box and which was invalidated by the validator framework.

So if a user enters 'foo@bar' as emailaddress the error message should
read 'foo@bar is an invalid email address' 

When a user enters 'foo2@bar' the error message should read 'foo2@bar is
an invalid email address' 

Thanks and regards,

Jeroen


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


Re: Simple validator question

Posted by Jeff Kyser <kt...@comcast.net>.
Here's roughly what you want to do to get 'Foo is an invalid email 
address':

Make sure you've added this to you ApplicationResources.properties
file as the 'email' rule expects a message named 'errors.email' - check 
the code for it
and you will see.

	errors.email={0} is an invalid e-mail address.

below is a snippet from my JSP where the e-mail entry field is declared:

             <td width="24%" align="right"><bean:message 
key="validateForm.emailField.displayname"/></td>
             <td width="76%" align="left">
                 <html:text property="emailField" />
                 <html:errors property="emailField" />
             </td>

and the associated entry in the validation.xml file...

             <field property="emailField" depends="email" >
                 <arg0 key="validateForm.emailField.errorname"/>
             </field>

other pertinent entries (for the code above) in the 
ApplicationResources.properties file:

	validateForm.emailField.displayname=<span class="formLabel">An 
email:</span>
	validateForm.emailField.errorname=Foo

works great - makes its own sauce...

-jeff

On Friday, October 3, 2003, at 03:25  AM, Jeroen Breedveld wrote:

> Hi all,
>
> Is it possible to supply the msg element with the value the user 
> entered
> in the form as the content of the arg element?
>
> My key errors.login.email.invalid is: {0} is an invalid email address
> So when a user enters 'foo' as an email adres I want an error message
> saying: 'foo is an invalid email address'
>
> Is this possible? Here is the code:
>
>     <form name="MailPasswordForm">
>       <field property="email" depends="required,email">
>         <msg name="required" key="errors.login.email.required"/>
>         <msg name="email" key="errors.login.email.invalid"/>
>         <arg0 name="email" key="email"/>
>       </field>
>     </form>
>
> Thanks and regards,
>
> Jeroen
>
> --
>
> X-Hive Corporation
> e-mail: jeroenb@x-hive.com
> phone: +31 10 2818080
> http://www.x-hive.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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