Struts Newsgroup (@Basebeans.com) wrote:

>Subject: Re: validation approaches
>From: Vic C <[EMAIL PROTECTED]>
> ===
>For complex validation you override the validate mehtod on the form bean.
>
>  
>
Actually in 1.1b1 you should rarely need to override the validate 
method.  Overriding the validate method buries/scatters business logic 
in source code and discourages reuse of validation rules.  Instead 
consider one of the following:

1) Combine existing rules
2) Write a regular expression
3) Write a custom rule.  (See: 
http://home.earthlink.net/~dwinterfeldt/overview.html#creatingValidators).

>Ex: Check to see if the clients new purchase order excedes therir unpaid 
>invoices and minus their credt line.
>
>  
>
In your circumstance I would do one of the following:

a) Validate it on the business services layer.  This rule seems core to 
the business as opposed to the application.  Perhaps it should be a 
check defined in a session bean (or manager class) that throws an 
business exception.  That way all applications interacting with your 
business services layer will be required to acknowledge this requirement.

b) write a custom rule with the following signature:

validation-rules.xml:
<validator name="adequateCredit"
       classname="com.nvisia.examples.struts.StrutsValidatorExamples"
       method="validateAdequateCredit"
       msg="errors.adequateCredit"/>

validation.xml:
<field property="orderTotal"
       depends="required,adequateCredit">
          <arg0 key="typeForm.orderTotal.displayname"/>
</field>
   
The code for the rule should be able to access the "user" and therefore 
can determine the values for "unpaid invoices" and "credit line"

Regards, Evan.

-- 
Evan Schnell, Technical Lead
nVISIA, Twin Cities  "Digital Architecture and Construction"
2 Meridian Crossings, Richfield, MN 55423
Voice: 612.243.2460 -- Fax: 612.243.2468 -- Mobile: 612.232.5972


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to