• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Best Practice for binding form values

 
Greenhorn
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: 28319
210
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.
 
I'm still in control here. LOOK at this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic