• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 1.1 Validator Vs Business Rules Validation

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been stepping through the Struts 1.1 Validator and had a question for you. I am developing a system that I need to upload a file, check its integrity and import it into my data store or return information about what errors are contained in it if it fails.

From my understanding of STRUTS Action classes must always strictly follow the presentation related activities and should not perform any business process. Use a Business Delegate to perform any business specific operations. Which I do. My business delegate checks the file for information making sure it is all correct.

Action classes should only perform data type validations. Any business rule validation is to be solely done by the Business tier components. Again, agreed.

My only outstanding question is how do I return error messages to the user about errors that were contained in the file as oppossed to the data type validations which I could just us ActionMessags/ActionErrors. I do not want to include this classes in my business delegate as they do not belong there in the same way business rules validation doesn't belong in the web tier of the application.

I would appreicatte if you could point out to me how this should be done. What should be returning to the web STRUTS tier to display any error messages.

Thanks,
Barry
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I wont agree with ur view that action has to do only with presentation layer ....its ofcourse one way of controller after actionservelt redirects to this ..........this on the basis of business logic judges where its hould go and passes that to actionservlet.

and that too u can call ur delegate only if ur file is valid .......so u better do that in actionclass(r else u can do this in formbean itslef if it doesnt need help of any of ur classes) and if its valid then only call ur business delegate

But if u want to put this strictly in to ur delegate itself then u throw one exception(custom exception r write a method which return boolean saying whther the file is valid) and then u forward back from the action with errors/messages added.......u need not(should not) include errors/messages in ur delegates

its not good idea
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Data level validation should be done before the Action ever gets hit - in the ActionForm and/or validation framework.

Actions should have business level validation or at least directly call validation utility class methods that return true or false. Another (and possibly better) option is to have your BDs throw exceptions for the Action to catch or return a null and have the Action handle it to display the appropriate error message.

The BDs should know nothing about what presentation framework you are using.
[ August 26, 2004: Message edited by: Marc Peabody ]
 
Barry O'Reilly
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The BDs should know nothing about what presentation framework you are using, agreed. As point in case for the BDs I am writing if I decide to change the Web Application Framework from STRUTS to say SPRING MVC I should not have to re-write validation code to check contents of the file are valid values, I want this to be done in BD class.

I understand the idea of throwing custom exceptions from the BD to be returned to the web layer but can I explain my specific problem and maybe you can tell me if the solution still works.

I am uploading a excel file populated with data that I wish to import into my data store. Hence after I perform form validation on the file in the web layer (i.e) file is under a certain size, has a validly formed name whatever... I pass an java.io.InputStream object to the BD with has the relevant package to access the contents of the excel file. Now I want to validate that the contents of the excel file are correct (i.e) values in certain rows and columns are what I expect them to be, say only integers in column A or dates in column C. The package allows me to perform this validation.

Ideally what I would like to do validate the entire excel file and save all exceptions that may be thrown detailing row number and column ( information that I can obtain in the package or programme code ) and return that data to the user back threw the BD up the the web layer and presented to them as an ActionError might be. (i.e) The value on Row 3 column 5 must be an integer. The value on Row 4 column 3 must be an date... and so on.

Will your solution cope with this? If so, can you detail to my how it might be done.

Thanks again for the help, much appreciated.



Barry
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic