Let me clarify. Say I have a list of products displayed depending on which category a user selects. Now say the user selects a different category, the list is repopulated with the new data and the user is happy. Now say the customer clicks the back button instead of using page navigation to go back to the first list. Although the page is displaying the old list, the bean where the list resides (and where the data for h:dataTable is bound) has the new list/data. Now, the customer clicks 'add to cart' on an item from the old list. As expected, the respective item in the new list is added to cart even though the customer wanted the one from the old list.
Let me try to illustrate to make this more clear.
<products.jsf> after the customer clicks on a different category (which i currently have shown on a sidebar)
After the user clicks his browser's back button, the page displays the first list but the bean contains the second list. If he tries to add Item 1 to cart from that page, it actually adds Item 4.
Now, this is about what I expected, but I was wondering if there is any way around this? Even if I can't make it add the correct item, I was hoping that it would recognize that something was wrong and maybe error out. JSF seems to handle multiple windows/tabs from the same session very poorly and also does not seem to work well with browser navigation.
So, any ideas? Am I setting it up completely wrong to begin with? Thanks in advance!
This is just a suggestion and I don't know for sure if it will solve your problem, but perhaps you could disable the "back" button?
Joined: Dec 17, 2010
I've thought about doing that, but I want to avoid it for several reasons. First and foremost, it's unprofessional. If I visited a website that purposely disabled my back button just because they didn't want to make their site work well with a browser, I would likely leave and never come back. Secondly, from what I've read it's extremely problematic trying to get it to work correctly in firefox.
This is more of a general question than a project specific one. I always seem to run into this same type of issue with JSF. In my previous projects, it was for internal systems that we could train users to not use browser navigation but for a public site this is by no means an option.
I was hoping there would have been a way to get the button to submit with like an ItemID field so I can check to make sure it's the item I have in the list (and fetch it from db otherwise) instead of just picking the corresponding row from the data and crossing my fingers.
Yes you're right this is a problem with jsf because it use POST for the request, but since JSF 2.0 you can use a GET request to make your page bookmarkable you can use a viewParam
with the new <h:button/> or <h:link/>.
I hope this information will serve you for what you need.
When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
Have you solved your problem? I also encounter the same problem in my web. As, the user requirement, we cannot disable the "browser back" function, thus, I have a work-around to solve the problem - when browser back the result page, click the link and incorrect detail page show.
2) After rerender, the result keep the correct items list instead of using browser caches. Thus, the correct page will show when click the link to go into the detail page
I had a similar issue once and I found the best solution was to create a PhaseListener that forces the control to refresh itself each time the app posts back. The idea being the user would at least see the current contents of the bean. They wouldn't be able to actually get their old data back, but at least they wouldn't accidentally put the wrong item in the shopping cart.
Joined: Apr 13, 2011
Yes, this is the idea. But, I think "browser back button" action will not trigger the server side action, how PhaseListener can help?