Just copy and past it into your new validation class:

    /**
     *  <p>
     *
     *  Return <code>true</code> if the specified object is a String or a
<code>null</code>
     *  value.</p>
     *
     [EMAIL PROTECTED]  o  Object to be tested
     [EMAIL PROTECTED]    The string value
     */
    private static boolean isString(Object o) {

        if (o == null) {
            return (true);
        }
        return (String.class.isInstance(o));
    }


One reason I can think of your validator needing to know the difference
between if validating for a String or say a String[] (returned if a
multi-select or if someone uses logic iterate to create 20 inputs with the
same name and that would use a String[])

The isString() method would tell you whether you need to test if the object
is a String[] because it wouldn't be a String (unless it is null by this
methods definition) so then you would do a check on the String[].length and
determine that nothing is there and throw the user back to the form.




-----Original Message-----
From: Erez Efrati [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, August 06, 2003 7:13 PM
To: 'Struts Users Mailing List'
Subject: RE: Validator

It's in the code of FieldsCheck.java. I was trying to create one of my
own validator and I saw these lines  there.

Erez

-----Original Message-----
From: Yansheng Lin [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 07, 2003 12:10 AM
To: 'Struts Users Mailing List'
Subject: RE: Validator

???

I don't see it in my validation-rules.xml.  Which version are you using?

-----Original Message-----
From: Erez Efrati [mailto:[EMAIL PROTECTED] 
Sent: August 6, 2003 3:33 PM
To: 'Struts Users Mailing List'
Subject: Validator



I am trying to figure out the code in struts.validator.FieldsCheck.java
in order to write one of my own.
Can someone explain what the purpose of the following lines of code in
all of the validateXXX() in Struts:

        validateIntRange (...) {

                if (isString(bean)) {
                        value = (String) bean;
                }
        ...
        }

        Is this really necessary?

Erez



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


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




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

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

Reply via email to