Thanks for your feedback guys, what I've got is some URL validation (just regexes, nothing magic) but I've also got some smaller regexes to detect stuff that looks like it should be an URL and patch it up (like 'www.google.com' into 'http://www.google.com/'). For now I've just got it in the validate() function of the view/form (not sure where struts terminology ends and local cruft terminology begins) and it's working just about perfect :) I'll definitely be coming back to these posts if I have any lists that need checking etc.
Cheers, -Josh -- "His comrades fought beside him, Van Owen and the rest... But of all the thompson gunners- Roland was the best." Josh McDonald Analyst Programmer Information Technology Ph: 61 7 3006 6460 Email: [EMAIL PROTECTED] >>> [EMAIL PROTECTED] 19/12/2005 1:39:02 pm >>> On 12/18/05, Josh McDonald <[EMAIL PROTECTED]> wrote: > > What's the best place to put input validation and possible repair? I actually prefer to do the validation checks in my DispatchAction. The reason being is that, inevitably, you'll end up with a case where you'll have some Lists you'll want to populate on your input JSP that are setup before you get to the JSP and if validation fails and you use the struts built in approach calling validate="true" in your action mapping, you'll end up with all kinds of problems when you are brought back to the JSP after validation fails (request scoped lists won't be in scope). Unless you use some other plans to keep the lists around (Session, reset,etc... all of which I don't like much and I talk more about here: http://www.reumann.net/struts/articles/request_lists.jsp). I find it saves you from headaches down the line if you just do your validation calls from your Action class. You can still use the validation framework (commons validator stuff that Paul mentions) to set up validation checks if that's your pleasure... it's just that the call to invoke those checks ends up being initiated from the Action. As an example: //notice the prep method which will put stuff back in request scope when validation fails and would also be used by other dispatch methods in this action class public ActionForward yourActionMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { YourForm yourForm = (YourForm)form; if (validationSuccessful(request, yourForm)) { //do stuff. return mapping.findForward(Constants.SUCCESS); } else { prep(request); return mapping.findForward(Constants.FAILURE); } } private void prep(HttpServletRequest request) { request.setAttribute(Constants.SOME_LIST_NAME, service.getSomeKindOfList()); } private boolean validationSuccessful(HttpServletRequest request, EmployeeForm form) { boolean isOk = true; ActionMessages errors = new ActionMessages(); //do your validation checks... //ie... if (form.getFirstName() == null || form.getFirstName().trim().length() == 0) { errors.add("firstName", new ActionMessage("errors.required", "First Name")); } //or you could even call the form's validate... //errors = form.validate( mapping, request ); //continue with other checks if (!errors.isEmpty()) { saveErrors(request, errors); isOk = false; } return isOk; } -- Rick *************************************************************************** Messages included in this e-mail and any of its attachments are those of the author unless specifically stated to represent WorkCover Queensland. The contents of this message are to be used for the intended purpose only and are to be kept confidential at all times. This message may contain privileged information directed only to the intended addressee/s. Accidental receipt of this information should be deleted promptly and the sender notified. This e-mail has been scanned by Sophos for known viruses. However, no warranty nor liability is implied in this respect. **************************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]