struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton" <>
Subject Re: Two questions: validation
Date Sun, 20 Jun 2004 16:12:17 GMT
1) You could either validate the page number in each of your Actions or in
the ActionForm. If you do it in the ActionForm the validate() method has the
ActionMapping, so you could check if the mapping name ties up with the page

        String action = mapping.getName();
       if (page == 1 && !("/myFirstAction".equals(action)))

Or you could do it in each of your actions in the execute() method...

   public ActionForward execute(ActionMapping mapping,
                                                         ActionForm form,

HttpServletResponse) {

         ActionErrors errors = new ActionErrors();
         if (form.getPage() != 4) {
         saveErrors(request, errors);
         if (errors.size() > 0)
            return mapping.getInputForward();


2) I think it would be a pain to access validator using the Struts
functions - they need it to be configured first, which is done in the XML
file. You could access the Commons Validator functions yourself directly

         Float result = GenericTypeValidator.formatFloat(value);
         if (result == null) {
            errors.add(field.getKey(), Resources.getActionMessage(request,
va, field));


----- Original Message ----- 
From: "Jacob Weber" <>
To: <>
Sent: Sunday, June 20, 2004 3:26 PM
Subject: Two questions: validation

> I have two questions on Struts' validation.
> 1. Let's say I have a multi-page form. Each JSP in the form points to a
> different action (or a different method of a DispatchAction), and passes
> the current "page" value to the action. It's possible for someone to
> pass the wrong value of "page" to an action (e.g. by passing it in the
> URL). This means that someone could call the final action in the
> sequence, pass page=0, and bypass all the validation. What's the
> recommended way to prevent this?
> 2. I have some validation rules that should only be checked under
> certain conditions. So I'm overriding the ValidatorForm.validate()
> method. Is there a clean way to access Struts' validation functions like
> validateFloat from this method, so I don't have to rewrite them?
> Thanks for any help,
> Jacob
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message