aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
 
 
subject: Strange ViewParams, GET Requests, AJAX behavior