wood burning stoves 2.0*
The moose likes JSF and the fly likes Is it possible to make controls on h:dataTable work after a back button has been used. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Is it possible to make controls on h:dataTable work after a back button has been used." Watch "Is it possible to make controls on h:dataTable work after a back button has been used." New topic
Author

Is it possible to make controls on h:dataTable work after a back button has been used.

John Tannel
Greenhorn

Joined: Dec 17, 2010
Posts: 23
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>


<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!

John
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

John,
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?

Good Luck,
Avi.
John Tannel
Greenhorn

Joined: Dec 17, 2010
Posts: 23
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.
Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

Hi John.

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.
Regards

Cesar


When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
calvin lai
Greenhorn

Joined: Apr 13, 2011
Posts: 2
Hi

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.

Temp solution:
1) Because the search result is kept, when "browser back" reRender the search result using javascript and a4j:jsFunction
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

<a4j:jsFunction name="invokeBack" reRender="SearchResult"/>
<rich:dataTable id="SearchResult" var="result" value="#{SearchMBean.searchResultList}" width="100%" rows="10" rowClasses="odd_row,even_row">
........
</rich:dataTable>
.........
<script type="text/javascript">
invokeBack();
</script>



If you have a final solution, would you please update it and help others... many thanks.

Reg,
A Hong Kong Junior Java Developer Assistant.
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 200

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.
calvin lai
Greenhorn

Joined: Apr 13, 2011
Posts: 2
Yes, this is the idea. But, I think "browser back button" action will not trigger the server side action, how PhaseListener can help?
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 200

I don't think it would. My case was different because I was using AJAX which keeps a continuous connection open between the server and the browser.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is it possible to make controls on h:dataTable work after a back button has been used.