重写 JSF 生命周期方法

发布于 2024-12-18 09:07:52 字数 223 浏览 1 评论 0原文

每当调用 JSF 页面时,我都需要设置一些值。因此,我查看了生命周期方法,认为我将能够重写,例如,restoreView 方法,以便我可以将页面的某些属性设置为 null。但我似乎找不到任何人这样做的例子。如果您能给我指出一个教程或示例,或者让我知道这样做的正确方法是什么 - 我将不胜感激。谢谢!

大声思考:也许在 xhtml 生成中有一个阶段,我可以在支持 bean 上调用方法,并在呈现其他内容之前设置我的值?

I need to set some values whenever a JSF page is called. So I looked at the lifecycle methods, thinking I'll be able to override, for example, the restoreView method so that I can set to null some of the page's properties. But I can't seem to find any example of anyone doing so. If you can point me to a tutorial, or an example, or let me know what is the right way for doing so -- I'd greatly appreciate it. Thanks!

Thinking out loud: maybe there is a phase in the xhtml generation when I can call a method on the backing bean, and set my values before anything else is rendered?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

谜泪 2024-12-25 09:07:52

根据您的问题历史记录,您正在使用 JSF 2.0。所以,这应该可以:

<f:event type="preRenderView" listener="#{bean.preRenderView}" />

但是

public void preRenderView() {
    this.some = null;
    // ...
}

这没有什么意义,我不禁有这样的印象:您正在以错误的方向寻找解决方案。

Based on your question history, you're using JSF 2.0. So, this should do:

<f:event type="preRenderView" listener="#{bean.preRenderView}" />

with

public void preRenderView() {
    this.some = null;
    // ...
}

This makes however very little sense and I can't help having the impression that you're looking for the solution in the wrong direction.

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