• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Best Practice for binding form values

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!
Posts: 21738
Android Eclipse IDE Tomcat Server Redhat Java 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.
Here. Have a potato. I grew it in my armpit. And from my other armpit, this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!