Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts Users »

Re: Validations - 'format' vs 'business'

Vic Cekvenich

2003-12-23

Replies:



Guido Garc�a Bernardo wrote:
> I really think that is a good aproach. At least one of the most simple
> and centralized.

Thanks, I take a lot of time to try to KISS.

> ...from a "pure struts" point of view someone can think that your
> solution is mixing the model with the view.
> I think ActionForm should remains as part of the view, or just a 'box'
> between the view and the controller.
> What do you think?

This is what I do as well when bus. rules are complex, so it's applied
as well, not just theory, by just ovreding the Sturts API validate().
I call the supper vlidate and capture the messages, and then to it I
append my custom messages as follows:
Then I can create a new MyBusRuleHelperClassForMyXYZFormBean:
MyBusRuleHelperClassForMyXYZFormBean rulz = new
MyBusRuleHelperClassForMyXYZFormBean()
messages rulz= rulz.check(this.getCollection()); // or what ever you
want to send in as data of the bean to the bus rule validator.
return messages;

So the action calls validate() on formbean and get messages to put in scope.
But...formBean validate() delegates the work outside of the formbean, in
the bus. rules clayer. That object often creates its own DAOs.

This also makes it very easy to unit test bus. rules outside of the
container.


>
> On the other hand, I _must_ expose business logic as a API for other
> projects. With this fact in mind, business methods should be
> implemented doing validations again (defensive programming, you need to
> think about possible errors from your users and don't assume
> anything...). HOW without duplicated code?

So your MyBASERuleHelperClass may be an interface or have an abstract
base. It should not import any Servlet or Struts jars.

If you want to go nuts, you can even use a rule engine in the bus. rules
layer .... as long as it's fast.
Since my bus rules relie on a fast self caching dao... I have no issues,
but I test w/ OpenSTA anyway.

.V





>
> Thank you again,
> Guido Garc�a Bernardo
>
> Vic Cekvenich wrote:
>
>> {repost}
>> I just override validate() method on formbean and do all there,
>> including super.validate() that reads validation.xml. In here I call
>> DAO's to do business validation also, ex: what is the available credit
>> for the client to place this order.
>>
>> Then in action I do this:
>> errors = formbean.validate();
>>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@(protected)
For additional commands, e-mail: struts-user-help@(protected)



©2008 junlu.com - Jax Systems, LLC, U.S.A.