Thanx Andy for the reply,
 
In validation.xml, I have configured identical like this:
 
         <field    property="userVerifyPassword"
             depends="required,maxlength,identical">
               <arg0 key="label.newclient.userverifypassword"/>
               <arg1 name="maxlength" key="${var:maxlength}" resource="false" />
               <arg2 key="label.newclient.userpassword"/>
               <var>
                    <var-name>maxlength</var-name>
                    <var-value>8</var-value>
               </var>
               <var>
                 <var-name>secondProperty</var-name>
                 <var-value>userPassword</var-value>
               </var>
         </field>

In validator-rules.xml, I have like this:
 
      <validator name="identical"
            classname="com.j_squad.benvia.util.CustomValidator"
               method="validateIdentical"
         methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
              depends="required"
                  msg="errors.identical">
            <javascript><![CDATA[
            function validateIdentical(form) {
                var isValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                oIdentical = new identical();
                for (x in oIdentical)
                {
                  var field = form[oIdentical[x][0]];
                  if ((field.type == 'hidden' ||
                       field.type == 'text' ||
                       field.type == 'password' ||
                       field.type == 'textarea') &&
                      (field.value.length > 0)
                      && field.disabled == false)
                  {
                   var secondProperty = oIdentical[x][2]("secondProperty");
                   var secondVal = form[secondProperty].value;
                   var fValue = field.value;
                   if ( fValue != secondVal)
                   {
                     focusField = field;
                     fields[i++] = oIdentical[x][1];
                     isValid = false;
                   }
                  }
                }
                if (fields.length > 0)
                {
                 focusField.focus();
                 alert(fields.join('\n'));
                }
               return isValid;
            }]]>
         </javascript>
      </validator>

The code in bold should get translated to:
                var formName = form.getAttributeNode("name");
                oIdentical = eval('new ' + formName.value + '_identical()');

I should be able to see the above two line in the generated HTML page (view -> 
source). But, I'm not able to these two lines. Not sure where I'm doing wrong.

Ratnakar.

Andy Schmidgall <[EMAIL PROTECTED]> wrote:
Ratnakar,

oIdentical should be an array containing all the objects that should be
validated for the current validator. This function (identical()) is
dynamically generated from your form and field definitions in
validation.xml. You will need to loop through the oIdentical array and
perform your validation on each of these objects. I don't recall offhand
what data is in the objects, but you should be able to figure out a bit
from the existing validators.

For example, it looks like the actual html form field from the page is
contained in the object, and could be referenced like this:

form[oIdentical[x][0]]

Where x is the index of the field. (0 would be the first field to
validate, 1 the second, etc.)

You can also reference the field arguments and variables if you have
those defined.

I hope this helps,
Andy

-----Original Message-----
From: Ratnakar Parakala [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 12, 2004 1:14 AM
To: [EMAIL PROTECTED]
Subject: Validator - Javascript question



Hi, 

I tried to write custom validation rule called "identical". But, if I
give oIdentical = new identical(); I didn't get any client side alert
messages. Hope this statement doesn't generate necessary javascript code
when the rule is configured and executed. I'm using Struts 1.2.1 (Beta).
Could sombody tell me the use of oTwoFields = new twofields(); statement
and how struts uses this statement to generate client side javascript. 

Thanx in advance, 

Ratnakar


---------------------------------
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!

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


                
---------------------------------
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!

Reply via email to