Hi Velmurugan,

  Thanks for the link.

  Iam learning struts, after going through this link only iam able to
modify my code.  The code given in this site works fine. But the problem is
in the "name field" modify depends="required, mask, minlength, maxlength",
In "address field" modify depends="required, mask" & in "email field" modify
depends="required, email" then wht will happens is :

if u enter a wrong name, address, email then the alert msg will be shown
only for name & address field but the alert msg will not be shown for the
email field.

  Is it some thing like that "All alert w.r.t required will be shown for
the first time", THEN "All msg w.r.t mask will be shown for the second
time", & so on?

 Pls have a look to my code below.

Regards
Rauf
================================================================

On 8/3/06, vel murugan <[EMAIL PROTECTED]> wrote:

Hi,
u refer the following site,

http://www.roseindia.net/struts/address_struts_validator.shtml

Thanks,
velmurugan

================================================================

On 8/2/06, Rauf Khan <[EMAIL PROTECTED]> wrote:

 Hi,

  Iam doing client side validations. Let me explain the problem. All field
are <html:text> & using struts 1.1

case 1:
 Name :    3456
 Password : abc
 Email : def

   In case1, if i click the submit button with the respective values, iam
getting alert msg "enter only characters for name" & "enter only numbers for
password" BUT its not displaying alert msg "Please enter a valid Email
address".

Suppose if i enter proper values for name & password field then it will
display alert msg "Please enter a valid Email address".

  As in case i all the 3 values are invalid so it should show all the 3
alert msgs in one alert.

  Only for name field iam checking that it should contain characters with
min. length=5 & max. length=6. For password field iam checking it should
contain only numbers. For email field iam checking to have a proper email
id. ALL field are required.

messageresources.properties:
---------------------------------------------
ComposeForm.OnlyNumbers =enter only numbers for password
ComposeForm.OnlyChars = enter only characters for fname

ComposeForm.InvalidEmail = Please enter a valid Email address.
 ComposeForm.fname.minlength = First Name cannot be less than  {1}
characters.
ComposeForm.fname.maxlength  = First Name cannot be greater than  {2}
characters.

 validation.xml
---------------------

<!-- compose form Validation-->
 <form name="InfoForm">
    <field  property="fname" depends="required, mask, minlength,
maxlength">
  <arg key=" ComposeForm.fname"  position="0"/>
  <msg name="mask" key="ComposeForm.OnlyChars"/>
  <var>
             <var-name>mask</var-name>
              <var-value>^[a-zA-Z]*$</var-value>
       </var>
  <msg name="minlength" key="ComposeForm.fname.minlength"/>
  <arg name="minlength" key="${var:minlength}"  resource="false"
position="1"/>
  <var>
      <var-name>minlength</var-name>
      <var-value>5</var-value>
  </var>
  <msg name="maxlength" key="ComposeForm.fname.maxlength"/>
  <arg name="maxlength" key="${var:maxlength}" resource="false"
position="2"/>
          <var>
       <var-name>maxlength</var-name>
      <var-value>6</var-value>
  </var>
 </field>

     <field  property="password" depends="required, mask">
          <arg key="ComposeForm.password"  position="0"/>
  <msg name="mask" key=" ComposeForm.OnlyNumbers"/>
  <var>
            <var-name>mask</var-name>
                 <var-value>^[0-9]*$</var-value>
       </var>
      </field>

 <field  property="emailaddress" depends="required, email">

       <arg key="ComposeForm.email"  position="0"/>
       <msg name="email" key=" ComposeForm.InvalidEmail"/>
      </field>

 </form>
Struts-config.xml
--------------------------

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">

<set-property property="pathnames" value="/WEB-INF/validator-rules.xml
,/WEB-INF/validation.xml"/>

<set-property property="stopOnFirstError" value="true"/>
</plug-in>

 JSP
------
<html:form action = "/some" method= "post" onsubmit="return
validateInfoForm(this);">
<table>
<tr><td>Name :&nbsp;</td><td> <html:text property="fname"
/></td><td><!--<html:errors property="fname"/>--></td></tr>
<tr><td> Password :  &nbsp; </td><td><html:text property="password" />
</td><td></td></tr>
<tr><td> Email : &nbsp;</td><td><html:text property="emailaddress"/></td>
<td></td></tr>
<tr><td colspan="3"> <html:submit/></td></tr>
</table>

<!-- Begin Validator Javascript Function-->
         <html:javascript formName="InfoForm"   staticJavascript="true"/>
<!-- End of Validator Javascript Function-->

</html:form>

Regards
Rauf Khan

 
=============================================================================================

 On 8/1/06, Adam Gordon <[EMAIL PROTECTED]> wrote:
>
> Rauf-
>
> Are you doing client or server-side validation?  Or both?
>
> W.R.T your multiple errors, there is an attribute you can set in your
> struts XML file, namely:
>
> |  <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
>    <set-property property="pathnames"
>                            value="/WEB-INF/validator- rules.xml
> ,/WEB-INF/validations.xml"/>
>    <set-property property="stopOnFirstError"
>                  value="true"/>
> </plug-in>|
>
> Note that you must be using Struts >= 1.2.0 for this feature, though I
> believe prior to 1.2.0, the behavior was to always stop on the first
> error.
>
> I'm a little confused by your explanation but it sounds like you're
> possibly missing the XML in your JSP for the email field since you say
> it doesn't show up - the other rationale is that it's a valid email
> address.
>
> Also, just an FYI, your password field does not have a max/min length
> validation.
>
> -Adam
>
> 
===================================================================================================




 Rauf Khan wrote:
> > Hi,
> >
> > I am trying to validate a simple form which has a name, password &
> > email field. I have validated that name field(html:text) should
> > contain only characters, password field(html:text) contains only
> > numbers & email field(html:text) should contain proper email id.
> >
> > When i enter only numbers in name field, only characters in password
> > field & an invalid email id then only alert msg "please enter only
> > characters"
> > is coming for name field & msg "pls enter only numbers for password
> > field' *BUT* no msg is coming for email field even though i have
> > entered a wrong email id. Also those two msgs are coming
> > simultaneously but i want like this, i mean to say when i click on
> > submit button first only msg for name field should show. Then again if
> > i click submit button then msg for password field should show & so on.
>
> >
> > Also suppose if i enter the proper name (only characs) , proper
> > password (only numbers) & if i enter the invalid email id then it will
> > show the
> > msg" please enter a valid email address".
> >
> > I am sending the following code for reference :
> >
> > Validation.xml
> > ---------------------
> > <!-- compose form Validation-->
> > <form name="InfoForm">
> >    <field  property="fname"
> > depends="required,mask,minlength,maxlength">
> >  <arg key="ComposeForm.fname"  position="0"/>
> >  <msg name="mask" key=" ComposeForm.OnlyChars"/>
> >         <var>
> >           <var-name>mask</var-name>
> >           <var-value>^[a-zA-Z]*$</var-value>
> >        </var>
> >  <msg name="minlength" key=" ComposeForm.fname.minlength"/>
> >  <arg name="minlength" key="${var:minlength}"  resource="false"
> > position="1"/>
> >      <var>
> >            <var-name>minlength</var-name>
> >            <var-value>5</var-value>
> >      </var>
> >  <msg name="maxlength" key="ComposeForm.fname.maxlength"/>
> >  <arg name="maxlength" key="${var:maxlength}" resource="false"
> > position="2"/>
> >           <var>
> >                 <var-name>maxlength</var-name>
> >                 <var-value>6</var-value>
> >          </var>
> > </field>
> >     <field  property="password" depends="required,mask">
> >           <arg key="ComposeForm.password"  position="0"/>
> >         <msg name="mask" key=" ComposeForm.OnlyNumbers"/>
> >             <var>
> >                         <var-name>mask</var-name>
> >                         <var-value>^[0-9]*$</var-value>
> >                     </var>
> >      </field>
> >      <field  property="email" depends="required,email">
> >          <arg key="ComposeForm.email"  position="0"/>
> >          <msg name="email" key=" ComposeForm.InvalidEmail"
> > position="0"/>
> >      </field>
> > </form>
> >
> >
> > MessageResources.properties:
> > --------------------------------------------------
> > #- validations for compose.jsp --
> > ComposeForm.fname = Please enter the Name.
> > ComposeForm.password = Please enter the Password.
> > ComposeForm.email = Please enter the Email.
> > ComposeForm.OnlyNumbers = Please enter only numbers
> > ComposeForm.OnlyChars = Please enter only characters
> > ComposeForm.InvalidEmail = Please enter a valid Email address.
> > ComposeForm.OnlyNumbersChars = Please enter only numbers & characters
> > ComposeForm.fname.minlength = First Name cannot be less than  {1}
> > characters.
> > ComposeForm.fname.maxlength  = First Name cannot be greater than  {2}
> > characters.
> >
> >
> > Thanks in advance.
> >
> > Regards
> > Rauf Khan
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to