I am doing my first JSF project and i am noticing some strange behavior with GET requests, ViewParams and Primefaces AJAX calls. I am sure my problems are probably just misunderstanding how JSF works.
I have a list of items which can be edited thru a link which looks like the meat of getItem bean is as follows
Clicking on the edit item link fires initGetItem and then setItemId as I would expect and the page display fine. However whenever the autocomplete AJAX calls are made it fires the setItem ID again which forced me to add the following code in the setItem Id
This seems to take care of resetting the item, seems like a hack but i can live with it for now. When the user takes the happy path click edit, update item,and click save everything works great. However when the user clicks the back button, edits the field and clicks save the initGetItem fires and not the setItemId so it inserts a new item. Any ideas?
posted 5 years ago
Instead of having the ID as the view Parameter and having getter/setter for the ID you could change the view parameter and getter/setters to deal with an Item entity directly. Then you would need to setup an entity converter for the Item entity. The converter would repesent the entity by ID and when an object was needed it would do the lookup based on the ID value passed in.
If you try this approach watch out for bug in JSF where you cannot inject objects into a converter. To overcome this you can use Seam 3 or use the BeanManager. You can read some about this here: