struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From taltun <>
Subject Re: Prevent persisting data when validation fails
Date Mon, 20 Jul 2009 13:33:26 GMT

I use JPA (hibernate) to persist.

An example of action that use prepare to load a person object from
transactional manager. When the validate fails and it return back to the
input page the request ends and the transaction persists the dirty user
object to database. The dirty user object should not be persisted if the
validation fails.:

public class PersonAction extends BaseAction implements Preparable {

private PersonManager personManager;
private Person person;

public void prepare() {
        person = personManager.getPerson(id);           

public String savePerson() {
       return SUCCESS;

public void validate() {
       if (person.firstName.length < 5 and person.firstName > 10) {
           addActionError("Firstname length should be between 5 and 10


taltun wrote:
> When submitting a form using manual validation in my action. Even when the
> validation fails and the action method supposed to be called is not called
> at all, the dirty data is persisted ?
> How can I prevent data from being persisted if the validation fails ?
> Note:  I use prepare method to load e.g an user object from a
> manager/service. And the data relates to the user object that is about. 
> -taltun

View this message in context:
Sent from the Struts - User mailing list archive at

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

View raw message