This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring Boot in Practice and have Somnath Musib on-line!
See this thread for details.
Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Best Practice for binding form values

Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
Saloon Keeper
Posts: 25849
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic