Hehe, I've just resolved my own issue!
The problem was my spring configuration. I needed to
specify scope="prototype" on each of my Struts 2 Action declarations.
Singleton actions were being created and thus previous field errors were
being carried over between requests.

I'm surprised this isn't a more common gotcha that should be highlighted in
the documentation.

Rgds

Murray

2009/10/23 Murray Furtado <murrayfurt...@googlemail.com>

> Hi,
> I'm using Struts 2.0.14 and validation annotations.  I have a
> UpdateUserAction class which implements ModelDriven and declares the
> execute() method with the following :
>
> @Validations( visitorFields = { @VisitorFieldValidator(message="",
> fieldName="model")} )
>
> My model is a User class which has a number of @RequiredStringValidators,
> etc.
>
> When I test the functionality I login to my app as a user with all it's
> fields populated (ie a valid user). I then update a dropdown box in the
> Update User jsp to the 'Select' value, to invalidate this property (declared
> with a @RequiredStringValidator).  Sure enough, when I submit the form, I
> get a field error telling me this is a required field. So far so good.
>
> However when I then correct that field and resubmit, I still get the error!
>  I've added debug code to the prepare() method of the UpdateUserAction and
> it shows that the previous field error is still present when I submit the
> corrected form.  This is strange because my understanding is that field
> errors should get cleared between requests, and the validation framework
> shouldn't fire until after the prepare() method has fired. So why am I
> seeing validation errors in the prepare method? And why aren't they
> clearing?
>
> What's even more frustrating is that I've downloaded the source code for
> the xworks 2.0.7 package, and attached as source in Eclipse Galileo, but
> then I can't set breakpoints in any of the xwork codebase to step through,
> as each time I try and open an xwork java file, it takes me to the .class
> file instead.
>
> Can anyone shed light on my problems as I can't see what I'm doing wrong?
>
> Thanks in advance,
>
> Murray
>
>
>

Reply via email to