Force JSF to refresh page / view / form when opened via link or back button -
i have jsf page posts data external page. data loaded jsf managed bean generates unique id in post data.
i have issue user clicks on checkout button navigates same page , presses checkout button again. post data has not updated. moreover, bean not invoked @ all. there anyway force jsf reload page , form data?
<form action="#{checkoutbean.externalurl}" method="post" id="payform" name="payform"> <input type="hidden" value="#{checkoutbean.uniqueid}" /> <input type="submit" value="proceed checkout" /> </form>
that page being loaded browser cache. harmless, indeed confusing enduser, because s/he incorrectly thinks it's coming server. can confirm looking @ http traffic monitor in browser's web developer toolset (press f12 in chrome/firefox23+/ie9+ , check "network" section).
you need tell browser not cache (dynamic) jsf pages. way browser request server page (and hereby triggering proper creation/initialization of managed beans , forth) instead of showing requested 1 cache.
generally, done simple servlet filter follows:
@webfilter("/app/*") public class nocachefilter implements filter { @override public void dofilter(servletrequest req, servletresponse res, filterchain chain) throws ioexception, servletexception { httpservletrequest request = (httpservletrequest) req; httpservletresponse response = (httpservletresponse) res; if (!request.getrequesturi().startswith(request.getcontextpath() + resourcehandler.resource_identifier)) { // skip jsf resources (css/js/images/etc) response.setheader("cache-control", "no-cache, no-store, must-revalidate"); // http 1.1. response.setheader("pragma", "no-cache"); // http 1.0. response.setdateheader("expires", 0); // proxies. } chain.dofilter(req, res); } // ... }
where /app/*
example url pattern on you'd turn off browser cache. can if necessary map on /*
, *.xhtml
or on servletnames={"faces servlet"}
.
if happen use jsf utility library omnifaces, can use builtin cachecontrolfilter
adding following entry web.xml
(which demonstrates direct mapping on facesservlet
, meaning every dynamic jsf page won't cached):
<filter> <filter-name>nocache</filter-name> <filter-class>org.omnifaces.filter.cachecontrolfilter</filter-class> </filter> <filter-mapping> <filter-name>nocache</filter-name> <servlet-name>facesservlet</servlet-name> </filter-mapping>
see showcase.
Comments
Post a Comment