-
1. Re: How to prevent page data reloading when click Back
blabno Feb 1, 2008 1:40 AM (in response to gus888)I guess, that backing bean gets initialized on every request, which may be due to too narrow scope.
-
2. Re: How to prevent page data reloading when click Back
arvhatte Feb 1, 2008 4:17 AM (in response to gus888)Hi gus888,
By default your browser shows you a page from its cache when you press the back button in your browser, except when that page has accepted POSTDATA, so was requested with the POST method instead of the GET method. The POST method is (generally) used when submitting form data en the GET method is (generally) used when simply retrieving information. In Seam the POST method is also used to propagate the conversation id (see http://labs.jboss.com/jbossseam/faq/#get, so if you try to go back to a page where you posted data or when in a conversation scope, your browser will try to re-post the data and therefore hit your server again, causing your data to be reloaded.
You can of course prevent this by making use of 'redirect' in your pages.xml to redirect to the new page after the POST is finished (basically accepting the POST, and then doing a new GET request to the new page). Another approach might be by storing data in a wider scope, which would still make a call to the server (when pressing the back button), but because the data is still present, it won't refetch that data from the database.
Hope this was helpful, if not, please let me know by replying again. If possible, also include your pages.xml and the two backing beans of the pages you're navigating between by using the back button.
Greetings,
Tim -
3. Re: How to prevent page data reloading when click Back
gus888 Feb 4, 2008 7:52 PM (in response to gus888)Hi Arvhatte, thank for your very detailed explanation. It is really helpful for me to understand the Seam framework.
However, I still couldn't figure out why I click Back, pages always act with back beans. When I run Seam samples, then click page Back, it seems it run on client, and pages seems don't have any action with server. Following is my partial code snippets. I really appreciate any help. Thanks in advance.@Name("profileLister") @Statefull @Scope(ScopeType.EVENT) public class ProfileListerBean implements ProfileLister { @Out(required=false, scope=ScopeType.PAGE) private List<ContactAddress> myContactAddressList; @Factory("myContactAddressList") public String loadContactAddress() { myContactAddressList = em.createNamedQuery("contactAddress.*:personId") .setParameter("personId", user.getId()).getResultList(); return "prfl-myContactInfo"; } } pages.xhtml <page view-id="*"> <navigation> <rule if-outcome="prfl-myContactInfo"> <redirect view-id="/profile/my/contact_info.xhtml"/> </rule> ....