开发者

How to refresh JSF view (Richfaces)

I have two JSF pages, index.xhtml [index] and main.xhtml [main]. On index, I have a dropDown, and when I select and submit, the app navigates to main after interacting with the backing bean.

The problem is this (given a dropDown populated with 'd1', 'd2', and 'd3'):

  • index: select 'd1'
  • main: shows page with d1 data. click exit. returns to index
  • index: main bean data items refreshed. select 'd2'
  • main: due to an error in the backing bean, main page shown but still with d1 data present

I've tried a number of ways to ditch the contents of the view when faces navigates back to the welcome index page, b开发者_C百科ut it's hanging around on the client side.

What's the most efficient way to clear the client component tree/view so when a user comes in and out of the main app page and selects new data, the old data is dropped?

Cheers


Put the bean in the request or view scope (thus not in the session scope) so that JSF will create new beans on new requests and instruct the webbrowser to not cache the page so that it won't redisplay the page with old input values from the cache.

Changing the bean scope is a trivial task. Disabling the browser cache for JSF requests can be done by a filter class which is mapped on <servlet-name>facesServlet</servlet-name> and does basically the following in doFilter() method:

HttpServletResponse hsr = (HttpServletResponse) response;
hsr.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
hsr.setHeader("Pragma", "no-cache"); // HTTP 1.0.
hsr.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜