I do all my validation in the action too - I need a lot of info from the b-tier about such things as which fields are mandatory when, etc... and it proved inconvienient (still quite possible - just required some ugly contortions - especially given some of the evil things Im doing in the RequestProcessor which you would rather not know about ;-> ) to do it in the form. I rather like to keep my forms stupid too (ie: just a simple data structure with getters and setters.) and put code that does the work of validating, directing traffic, and calling the business objects together in the same class. Not so OOPy, but I find it saves time and makes it easier to locate and work on things.
In fact most of my crud actions are subclasses of a common abstract (dispatch) action , which has an abstract validation method it calls and then returns the user to the form complete with actionErrors as normal if the validation fails. (Im cheating a bit , in that if my save method fails due to validation errors, rather than doing a forward back to the input (which is in fact that same action (Im not using JSPs but rather a homebaked rendering technique based around DOM - which needs an action to set up the renderers for the view)) I simply make a direct call to my update method...) If you are validating in the action , you can get the relative path(*) to return to if validation fails from mapping.getInput() which returns a string - the contents of which are the value of the input attribute in your action mapping in struts config. You could probably build an ActionFrward out of this and return it from the action. Since you would be forwarding (ie: make redirect=false) all the stuff in your request context will be preserved and sent back to the input - including the ActionForm populated from the request. The code struts uses to call validation in your actionForm and return to the input if it fails may (in 1.1) be found in the processValidate() method of the RequestProcessor. (*) Struts 1.1b2 appears to allow the input to be the name of a forward instead of a path now, but I havent had time to examine this new functionality yet. -----Original Message----- From: David Graham [mailto:dgraham1980@;hotmail.com] Sent: Tuesday, October 29, 2002 09:05 To: [EMAIL PROTECTED] Subject: Re: error checking in Action Why do you "need" to move error checking into an action? Why not just let the form bean do it's job and validate itself? Have you looked at using the validator? Validation belongs in the form bean; actions' main job is to direct traffic and execute business layer methods. David >From: "Mark Silva" <[EMAIL PROTECTED]> >Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]> >To: "Struts Users Mailing List" <[EMAIL PROTECTED]> >Subject: error checking in Action >Date: Mon, 28 Oct 2002 16:54:39 -0800 > >I need to do some extensive error checking, and need to move this into an >action class. > >my question is when i identify an action, how i forward back to the >previous page (the same way a form class would). is there a method to take >care of this? or do i need to setup all the passed values in the request >again and do an ActionForward to the appropriate page? > >thanks, >mark > > > >-- >To unsubscribe, e-mail: ><mailto:struts-user-unsubscribe@;jakarta.apache.org> >For additional commands, e-mail: ><mailto:struts-user-help@;jakarta.apache.org> _________________________________________________________________ Unlimited Internet access -- and 2 months free!� Try MSN. http://resourcecenter.msn.com/access/plans/2monthsfree.asp -- To unsubscribe, e-mail: <mailto:struts-user-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org> -- To unsubscribe, e-mail: <mailto:struts-user-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

