Loading an Entity in the prepare method is a common use-case.
If you're allowing an Entity to be updated directly from the JSP you'll probably need the prepare-params-prepare (set params including entity's ID, params loads the existing entity, prepare sets the params on the entity instance)

I prefer not to do that because you're dirtying an Entity and consequently need to rollback the entire transaction in the case of a validation error or exception. ie. you dirty the Entity before S2 validation so it will be committed when the EntityManager/Session commits.

It is however a productive way to work if you can control that as you don't need to double-handle anything (ie. write to a bean, validate, update entities(s) behind a service layer). I prefer this more-effort approach except in the simplest of cases.

GF wrote:
I want to edit an entity, i.e. a Message
i would set the .jsp field this way

<s:textfield name="message.title"  />

on the MessageAction i would have a "edit" method that takes the
messageID and then call the business service to load the Message
object, so in the .jsp the file the textfield are loaded with the
current value.
when I submit the form, Struts2 will try to call
getMessage.setTitle("...") and so on, and it try to instatiate a new
Message object.
My idea is to create the object (loading it from hibernate calls on
the business service) in the prepare method, in this way when struts
will call getMessage.setTitle, it will set the new values on the
object loaded from the DB.
My worry is that this idea rely on the fact that the prepare
interceptor is called before the parameters interceptor.
What you think?
any better idea?

thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to