Hi David,

sorry that this isn't clear.

A validation rule does nothing magical. It validates something, anything, and if it returns false, RIFE knows that the validation didn't succeed. It will then obtain the error and the validated subject name to indicate what went wrong.

You don't have to implement getBean and setBean if you extend AbstractValidationRule or PropertyValidationRule, these methods simply allow RIFE to provide you with an instance of the bean to validate, and provides you with a standard method to retrieve it from. You'll almost always store this bean in an member variable of your class.

Now, it's up to you to obtain the value from that bean, to validate it and to return true or false (and the appropriate error and subject name). For inspiration I suggest that you look at the implementation of the existing validation rules.

For example:
http://rifers.org:8088/viewrep/rifers/rife/trunk/src/framework/com/ uwyn/rife/site/ValidationRuleLimitedLength.java?r=2930

I hope this clarifies things.

Best regards,

Geert

PS.: I know that these classes need javadocs, if you want to help the project out, this is an ideal way to contribute something.

On 17-feb-06, at 13:42, David Herbert wrote:

Geert,

Thanks for this. Some more questions I'm afraid.

To add custom validation rules, all you need to do is add the
following method in activateValidation:
addRule(your_validationrule_instance).

Ok. I've added the rule to activateValidation in my bean class (UserInfo)
thus:

addRule( new LoginValidationRule() );

Your validation rule has to implement the following interface:
http://rifers.org/docs/api/com/uwyn/rife/site/ValidationRule.html

Otherwise, this abstract base class will probably provide what you need:
http://rifers.org/docs/api/com/uwyn/rife/site/
AbstractValidationRule.html

Within my bean I have (at least for now) created this class:

   /**
     * Extra validation rule for the login name:
* Must either be an email address, or be in the list of special users
     */
    private class LoginValidationRule extends AbstractValidationRule {

        public LoginValidationRule() {

        }

        public String getSubject() {
            return( "login" );
        }

        public ValidationError getError() {
            return( new ValidationError.INVALID( "login" ) );
        }

        public boolean validate() {

            ValidationRuleEmail isEmailRule = new
ValidationRuleEmail( "login" );
            ValidationRuleInList inSpecialListRule = new
ValidationRuleInList( "login", new String[] { "admin", "guest" } );
return( isEmailRule.validate() || inSpecialListRule.validate() );

        }

    }

I am a bit unsure of what all the methods I need to implement actually do. I am happy to use ValidationError.INVALID in getError() for now, though I might want to create a new class that implements ValidationError but one thing at a
time!

Questions:

(1) I assume that in creating the validation rules in validate() above, RIFE figures out the actual value of the submitted parameter "login" it needs to
work with?
(2) What do I do to implement setBean() and getBean(), and do I need to?

Thanks,

David.


--
Geert Bevin                       Uwyn bvba
"Use what you need"               Avenue de Scailmont 34
http://www.uwyn.com               7170 Manage, Belgium
gbevin[remove] at uwyn dot com    Tel +32 64 84 80 03

PGP Fingerprint : 4E21 6399 CD9E A384 6619  719A C8F4 D40D 309F D6A9
Public PGP key  : available at servers pgp.mit.edu, wwwkeys.pgp.net


_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to