jsf basic question about request scope
I think this is a jsf basic question but I simply require a little bit of explanation..
I have a login page where I have a link to a CreateAccount page:
<div
id="TGOV_popAccount"
style="float: left; margin-left: 60px !important;"><a
href="/createAccount.jsp">Create Account</a></div>
Now, this jsp page open a jsf facelet one (yeah, ugly design):
createAccount.jsp:
<jsp:forward page="/WEB-INF/jsf/account/createAccount.jsf" />
so now, this createAccount.jsf has a CreateAccountBean as the backing bean with request
scope. The first time I go to create account page the constructor calles the init method (for some reason the @PostConstruct is not automatically called, that'开发者_如何学JAVAs why I call it from constructor...maybe because of that jsp forward?)
public CreateAccountBean() {
init();
}
@PostConstruct
public void init() {
userLoginVo = new UserLoginVo();
logger.info("init called");
}
If a open again my login page and go again to createAccount page, the init is no longer called and I do not understand why... Having a request scope, it should be reinitialized in this situation, right?
Can you explain me why it fails?
Thanks.
Get your JSF out of /WEB-INF
and link to it immediately.
As to the initialization failure, likely the page is been served from the browser cache instead of from the server. Create a Filter
which is mapped on <servlet-name>facesServlet</servlet-name>
and does the following job in the doFilter()
method:
HttpServletResponse res = (HttpServletResponse) response;
res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
res.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);
精彩评论