jsf关于请求范围的基本问题
我认为这是一个 jsf 基本问题,但我只需要一点解释。
我有一个登录页面,其中有一个 CreateAccount 页面的链接:
<div
id="TGOV_popAccount"
style="float: left; margin-left: 60px !important;"><a
href="/createAccount.jsp">Create Account</a></div>
现在,这个 jsp 页面打开一个 jsf Facelet 一个(是的,丑陋的设计) :
createAccount.jsp:
<jsp:forward page="/WEB-INF/jsf/account/createAccount.jsf" />
所以现在,这个 createAccount.jsf 有一个 CreateAccountBean 作为具有 request
范围的支持 bean。 第一次我去创建帐户页面,构造函数调用 init 方法(由于某种原因,@PostConstruct 不会自动调用,这就是我从构造函数调用它的原因......也许是因为该 jsp 转发?)
public CreateAccountBean() {
init();
}
@PostConstruct
public void init() {
userLoginVo = new UserLoginVo();
logger.info("init called");
}
如果再次打开我的登录页面并再次进入createAccount页面,则不再调用init,我不明白为什么......有一个请求范围,在这种情况下应该重新初始化,对吧?
你能解释一下为什么失败吗?
谢谢。
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's 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的 JSF 从
/WEB-INF
中取出并立即链接到它。至于初始化失败,该页面可能是从浏览器缓存而不是服务器提供的。创建一个映射到
facesServlet
的Filter
并在doFilter()
中执行以下工作> 方法: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 thedoFilter()
method: