• Post Reply Bookmark Topic Watch Topic
  • New Topic

Best Practice for binding form values  RSS feed

 
Darren Briaris
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Newbie question!

I have a simple jsf page that currently binds the form items to a session managed bean. On submit of the page, the session bean is then persisted to the database.

I have a concern if the page is used to edit existing data in the session bean, and the user decides to cancel the update, how do I stop this being in the session?

Is there a best practice for this in JSF? Should I have all form fields binding to a backing bean object and only then , on submission of the form, update the session bean?

I need to cater for the fact that a page may be updated via a address lookup button (for example) which will populate some of the values on the form.

Any help appreciated!
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's usually better not to attempt to use Domain Model (persistence) objects as backing beans. This is one of the reasons. You're better off creating a UI model object backing bean that presents the model object as one of its properties. Or, alternatively, acts as a fa├žade for the domain model object.

If you are using an ORM such as Hibernate/JPA, you can obtain a domain model object and detach it. Once detached, the only way changes made to the model object will reflect back into the database is to re-attach (merge) it, so if you want to back out, you can simply discard the detached object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!