• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setting values of a bean

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to update my database using jsf. When someone selects something on my page the info is displayed of that something. On that page the user then can change some of the values with a h:inputfield. Then I want to update those changes to the database. My problem is: when the user select the something a bean is created with every info from the database including the primary key. Then I display some of the items but not the primary key of course, because I don't want the user to change it. When the user clicks save a new bean is created (because I want all of my beans to be request scoped) with all the new items but the primary key is never set! Does anyone know how I can set the primary key in my bean without the need of putting a h:inputfield on my jsf page? I'm using jsf 1.2 if it makes any difference...

thanks in advance.

edit: When I am using the bean as a session scoped one, the first time someone tries to update the values it doesn't work but the 2nd time it does.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
? Is this possible?
 
Saloon Keeper
Posts: 27752
196
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 done all the time. There are several ways to do it, but one of the most effective is to keep a copy of the record key in a session-scoped object.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean that when someone enters my "select page" other beans will be made with only the key in them?
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
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
I don't know all the details here, but a common JSF approach is to use a dataTable to display a list of items, then users click on an item in that list to edit it.

The dataTable has to be session-scoped to work properly, and the backing object for each row in the table usually has some way to obtain the record key, so a simple dereferencing of the DataModel's currentRow object should be able to provide that for you.

Passing keys out to the client isn't a very secure thing to do anyway. Bad People have been known to alter the keys before returning them in order to attack some other record entirely. Better to keep the record ID on the server, and that means session-scope or wider.
 
T Tberg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok thanks, I solved it:D
 
We don't have time for this. We've gotta save the moon! Or check this out:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic