jsf关于请求范围的基本问题

发布于 2024-11-08 18:20:16 字数 938 浏览 4 评论 0原文

我认为这是一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感情废物 2024-11-15 18:20:16

将您的 JSF 从 /WEB-INF 中取出并立即链接到它。

至于初始化失败,该页面可能是从浏览器缓存而不是服务器提供的。创建一个映射到 facesServletFilter 并在 doFilter() 中执行以下工作> 方法:

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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文