jQuery in Action, 2nd edition*
The moose likes JSF and the fly likes Strange ViewParams, GET Requests, AJAX behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Strange ViewParams, GET Requests, AJAX behavior" Watch "Strange ViewParams, GET Requests, AJAX behavior" New topic
Author

Strange ViewParams, GET Requests, AJAX behavior

Fred Lehr
Greenhorn

Joined: Nov 03, 2010
Posts: 1
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


getItem.xhtml


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?

Ryan Slominski
Ranch Hand

Joined: Nov 05, 2010
Posts: 33
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:

seam-faces-makes-jsf-entity
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange ViewParams, GET Requests, AJAX behavior
 
Similar Threads
Problem with Web Service Response
Storing of Data
Exception while inserting a row using Hibernate
Simple prob
CascadeType.PERSIST not working