• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 90
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic