支持 Ajax 的 JSF 框架中不必要的会话 Bean

发布于 2024-09-12 09:31:11 字数 268 浏览 1 评论 0原文

我注意到,当使用像 Richfaces 这样的 Ajax 重型 JSF 1.2 实现时,您在某种程度上被迫声明比您想要的会话范围内更多的托管 bean,以便可以跨多个 Ajax 请求维护状态;有些组件会停止工作。

例如,我最近开发了这个应用程序,在该应用程序中,我必须将几乎所有 JSF Backing Bean 声明为会话范围,以便组件“x”正常工作。有没有办法解决这个问题,您是否认为这是一种不好的做法,或者只是在 JSF 1.2 中使用支持 Ajax 的组件所付出的代价。

提前致谢。

I've noticed that when using Ajax heavy JSF 1.2 implementations like Richfaces you're somehow forced to declare more managed beans than you'll want as Session scoped so that state can be maintained across multiple Ajax requests; there are components that will just stop working.

For instance, I developed this application lately in which I had to declare almost all my JSF Backing Beans as Session Scoped in order to have component "x" working. Is there a way out of this, do you consider it a bad practice, or is just the price to pay for having Ajax enabled component in JSF 1.2.

Thanks in advance.

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

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

发布评论

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

评论(2

维持三分热 2024-09-19 09:31:11

会话范围 Bean 会增加内存使用量。

另一个可用的范围是 View Scope - 这允许在请求之间保留 bean 的状态,同时用户仍处于同一视图上。

如果您使用的是 JSF2,请考虑在 bean 名称上方使用 @ViewScope

    @ViewScope
    public class myBean{
     ..
     }

如果您使用 RichFaces 和 JSF1.2,请考虑在下面使用 视图中的。例如:

<a4j:keepAlive beanName = "#{myBean}"/>

此处阅读更多信息

Session scope beans increase memory usage.

Another available scope is View Scope - This allows to keep a state of a bean between requests, while the user is still on the same view.

If you are using JSF2, please consider using @ViewScope above the bean name:

    @ViewScope
    public class myBean{
     ..
     }

If you use RichFaces and JSF1.2, consider using <a4j:keepAlive /> under <f:view> in the view. for example:

<a4j:keepAlive beanName = "#{myBean}"/>

Read more info here

烟织青萝梦 2024-09-19 09:31:11

另一种选择是使用 Seam 对话。另外,我不会说组件停止工作,它们仍然工作......这是您的逻辑需要在服务器上维护某种状态。

Another option is to use Seam conversation. Also, I wouldn't say components stop working, they still work.. it's your logic that needs to maintain some sort of state on the server.

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