...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?
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?
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();
hth, .V
Guido Garc�a Bernardo wrote:
Hi,
I have a design doubt... I must validate data coming from a form. This consist typically of:
- 'format' validations (i.e. a field is not empty or it is numeric) that I do in the validate method of the ActionForm
- 'business' validations that usually require a DB access
I actually do 2 steps (actions) per operation. One of them prepare the data and the second one does the operation itself. And here comes my first question: ��is there any other better aproach?? Maybe something similar to a Tiles Controller to prepare the data...
class PreOperationAction extends Action {
public ... execute ( ... ) {
// Create JavaBeans to populate html selects and several inputs (requires DB access) and include them in the request
// Forward to error/success jsp
}
}
class PostOperationAction extends Action {
public ... execute ( ... ) {
// Get data from ActionForm
// Business validations (the selected values and inputs are valid from the business point of view)
// Execute business logic (encapsulated in external business logic classes)
// Forward to error/success jsp
}
}
At this point I don't know what is better (from a MVC perspective).
1. Do it as actually, that is, doing business validation before business logic. This way I think I can't expose the business logic as an API or as a web service.
2. Include all the validations (business and format) into the business logic classes. This way I must duplicate format validations
3. Doing a OperationValidations class (? only a vague idea)
4. Is there any pattern or any best practice related? Does Validator Plugin allow complex business validations?
Finally, I need your opinion about handling validation errors:
1. Throwing an Exception from the business logic classes and catch it in the Action (or declare the exception in struts-config.xml)
2. Returning null (or -1, or a no-sense value) from the business logic classes
3. Any other way...
Thank you very much, Guido Garc�a Bernardo.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

