Multiple input for struts validation


Web tier: servlets, JSP, Web frameworks: Multiple input for struts validation

  1. Multiple input for struts validation (4 messages)

    Hi Is there a way to have multiple input attributes in struts validation. I need to perform validations for more than one jsps. All the jsps have a common action and they all have a common form bean too. But each jsp has its own set of validations to be performed. Ex: I have a wizard kind of application. In that each jsp has different fields. They all have a common action and form bean. In such a scenario I cannot have seperate actions / form beans. How do I do the validation using struts validator? Pls let me know ASAP.. Thank you for your help.
  3. In your ActionForm: @Override public String getValidationKey(ActionMapping mapping, HttpServletRequest request) { return ( validationKey == null ) ? super.getValidationKey( mapping, request ) : validationKey; } /** * Used by MyAction. * Package access. */ void setValidationKey( String validationKey ) { this.validationKey = validationKey; } In your MyAction.execute(): myForm.setValidationKey( UNIQUE_KEY ); ActionMessages errors = myForm.validate( mapping, request ); if( errors != null && !errors.isEmpty() ) { saveErrors( request, errors ); return mapping.getInputForward(); }
  4. Thank you for your suggesstion. How do I use the approach with dispatch action. Also I do not use validation.xml. I will put the needed validations in the form beans validator method.
  5. You can keep a hidden field or session scope variable to determine which page/screen of the form you are currently on, and if the page no==1 then you know the set of fields on that particular screen, and validate accordiongly, and at the end screen , say for example "5" , you can finish the whole validation and do the forward..!