Sorry, I have made mistake, you will need EventConstants.VALIDATE event instead of EventConstants.VALIDATE_FORM, and also you need component id. But to specify this component id you have to override property editor as I've mentioned before.
On Mon, Nov 19, 2012 at 6:01 PM, Nicolas Barrera <nbarr...@gmail.com> wrote: > Thank you so much Ivan, > > I 'd rather use option number 1 as I like to leave transaction management > as I 've already got it. > > Related to the first option you mentioned and the code you posted... > it's not necessary to override the name property with <p:name> ain't it? > > cheers, > > Nicolás.- > > > On Mon, Nov 19, 2012 at 8:11 AM, Ivan Khalopik <ikhalo...@gmail.com> > wrote: > > > You can try 2 options: > > > > 1. Use validation by name to prevent name changes before request to DB. > It > > will be executed before name property will be assigned to new value: > > > > @OnEvent(value=EventConstants.VALIDATE_FORM, component="nameField") > > public void validateName() { > > //... > > } > > > > <t:beaneditform t:id="user" submitlabel="message:create-user"> > > <p:name> > > <t:label for="nameField"/> > > <t:textfield t:id="nameField" value="user.name"/> > > </p:name> > > </t:beaneditform> > > > > 2. Retrieve profile in separate transaction with uncommited read > isolation. > > > > > > On Fri, Nov 16, 2012 at 5:15 PM, Nicolas Barrera <nbarr...@gmail.com> > > wrote: > > > > > Hi all, > > > > > > I 'm not using the tapestry-hibernate module. > > > > > > I 'm using spring configured hibernate, tapestry-spring, and an open > > > session in view spring filter. > > > > > > I can use BeanEditForm to create a new entity and save it, the problem > is > > > when trying to modify an existing entity. > > > > > > My problem is that during activation after submission I get an > unmodified > > > instance of the entity from the database, > > > after that the beaneditform modifies the properties of that entity and > > > during validation when the DAO performs a criteria query > > > by name changes on the entity object are being flushed to the database. > > > > > > I wonder how does the tapestry-hibernate module handles these kind of > > > trouble, > > > > > > Here is my code: > > > > > > @OnEvent(value=EventConstants.ACTIVATE) > > > > public void activate(Long profileId) { > > > > profile = this.profileDAO.load(profileId); > > > > } > > > > > > > > @OnEvent(value=EventConstants.PASSIVATE) > > > > public Long passivate() { > > > > return this.profile.getId(); > > > > } > > > > > > > > @Log > > > > @OnEvent(value=EventConstants.VALIDATE_FORM) > > > > public void validate() { > > > > try { > > > > // validating if the new name already exists, if it does > > fail > > > > validation > > > > this.profileDAO.getByName(profile.getName()); > > > > > > > > > > > > > > this.profileForm.recordError(messages.get("error.profile.already.exists")); > > > > } catch(ModelException me) { > > > > // validation is expecting this exception, I know it's > > nasty > > > > but... > > > > } > > > > > > > > } > > > > > > > > @OnEvent(value=EventConstants.SUCCESS) > > > > public Object persistNewUser() throws ModelException { > > > > this.profileDAO.save(profile); > > > > return ListProfiles.class; > > > > } > > > > > > > > > > tried evicting the instance from the session on prepareForSubmit but > then > > > (as the entity is lazy) beaneditform fails trying to set the > properties. > > > > > > Right now I 'll avoid using beaneditform for modification pages but I > 'd > > > definitely prefer using it! > > > > > > thank you so much, > > > > > > cheers > > > > > > Nicolás.- > > > > > > > > > > > -- > > BR > > Ivan > > > -- BR Ivan