1

I'm a beginner in JSF and I´m having the following problem: I have a view with a backbean that I fill some values ​​to perform a search and display results. When I go out and return the application, the values ​​from the latest request remain there. I use the following annotations in my bean:

@Component("requestBeneficioCustosController")
@ManagedBean(name = "requestBeneficioCustosController")
@RequestScoped
public class RequestBeneficioCustosController implements Serializable {
...

I thought with the @RequestScoped annotation, the values of the bean would be cleaned after leaving the page. Does not work that way? Can you help me?

Thank you in advance

fabiogm
  • 25
  • 1
  • 3

1 Answers1

1

You're likely facing a page from the browser cache. You need to instruct the browser to not cache the JSF pages. This is the best to be achieved by a Filter which is mapped on an URL pattern of interest (*.jsf for example) and does the following job 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);
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hello BalusC. Thanks for your help. I did not know about filters, I ´m seeking more information to apply your tip. It´s what made ​​most sense so far.Thank you very much. (Sorry my english) – fabiogm May 25 '11 at 12:49
  • Check our wiki page on `[servlet-filters]` tag http://stackoverflow.com/tags/servlet-filters/info – BalusC May 25 '11 at 12:50
  • Hi BalusC. Where effectively the object "hsr" , instance of HttpServletResponse, is considered in this code ? The chain.doFilter(req,resp) does not seem to consider it. – fabiogm May 25 '11 at 14:08
  • It does not copy the instance or something. It's the **same** instance. Java is OO, not procedural or something. The cast just allows access to more specific methods which are not present in the superclass. Did you try to run it anyway? – BalusC May 25 '11 at 14:11
  • I know it is OO, but I do not see where, or how, HSR effectively influences in response, in this code. Yes I ran and seems not take effect, but I'll keep trying anyway. Thank your attention. – fabiogm May 25 '11 at 14:44
  • The filter method argument is declared as `ServletResponse`. But when invoking a HTTP request on it, it's **actually** a `HttpServletResponse`, which is a subclass of `ServletResponse`. So the cast is safe. The `setHeader()` methods are present on `HttpServletResponse` only. So the cast is mandatory. The cast does not change the instance's internals or something. It just changes the way how the code can access it. It doesn't matter whether you pass `hsr` or `response` through `chain.doFilter()`. It's the **same instance** after all. – BalusC May 25 '11 at 14:47