• Post Reply Bookmark Topic Watch Topic
  • New Topic

setting values of a bean

 
Niels Tielenburg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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.
 
Niels Tielenburg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
? Is this possible?
 
Tim Holloway
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Niels Tielenburg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 18417
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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.
 
Niels Tielenburg
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok thanks, I solved it
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!