• 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

Strange ViewParams, GET Requests, AJAX behavior

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic