a4j:keepAlive 在渲染部分

发布于 2024-12-28 02:27:52 字数 566 浏览 0 评论 0原文

我想知道(或者可能遭受一些 keepAlive 副作用)关于(猜猜是什么?) a4j:keepAlive 在 jsp 页面中的位置...

之间有什么区别...可以说:

<a4j:keepAlive beanName="myBean"/>
<h:panelGrid rendered="#{myBean.sth}">
    <%-- some other stuff-->
</h:panelGroup>

<h:panelGrid rendered="#{myBean.sth}">
    <a4j:keepAlive beanName="myBean"/>
    <%-- some other stuff-->
</h:panelGroup>

myBean 的范围仅限于请求。

仅当 sht 属性设置为 true 时,jsp 页面中的 keepAlive 位置是否会导致扩展 bean 存在,或者无关紧要(发生 keepAlive 的位置)?

I'm wondering (or possibly suffering from some keepAlive side effects) about location of (guess what?) a4j:keepAlive in jsp page...

Is there any difference between... lets say:

<a4j:keepAlive beanName="myBean"/>
<h:panelGrid rendered="#{myBean.sth}">
    <%-- some other stuff-->
</h:panelGroup>

and

<h:panelGrid rendered="#{myBean.sth}">
    <a4j:keepAlive beanName="myBean"/>
    <%-- some other stuff-->
</h:panelGroup>

myBean is scoped to a request.

Does keepAlive location in jsp page cause to extend bean existence only if sht property is set to true, or it doesn't matter (where keepAlive occurs)?

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

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

发布评论

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

评论(1

灰色世界里的红玫瑰 2025-01-04 02:27:52

将 keepAlive 标记放在 jsp 中的位置没有区别。但是keepAlive标签组件和@KeepAlive注解之间有很大的区别。

标签组件

<a4j:keepAlive bean="myBean" />
<!-- some stuff -->

注释

@KeepAlive
public class MyBean {
    //some stuff...
}

两者之间的主要区别是,如果您想将 bean 中的属性绑定到 JSP 中的组件,则第二种更好。假设您有这样的场景:

<rich:dataTable binding="#{myBean.hdtMyDataTable}">
    <!-- columns here -->
</rich:dataTable>

如果您使用第一种方法,那么 keepAlive 根本不起作用,并且将在每个请求中重新创建 bean。使用第二种方法,您的 Bean 将为用户在您的视图中可以执行的每个请求创建一次。

另外,如果您只想让 bean 为 ajax 请求保持活动状态,请不要忘记将 ajaxOnly 属性设置为 true。

There is no difference where you put the keepAlive tag in the jsp. But there is a big difference between the keepAlive tag component and the @KeepAlive annotation.

Tag component

<a4j:keepAlive bean="myBean" />
<!-- some stuff -->

Annotation

@KeepAlive
public class MyBean {
    //some stuff...
}

The main difference between is that second is better if you want to bind attributes in your bean to components in your JSP. Let's say, you have a this scenario:

<rich:dataTable binding="#{myBean.hdtMyDataTable}">
    <!-- columns here -->
</rich:dataTable>

If you use the first approach, then the keepAlive won't work at all and the bean will be recreated in every request. With the second approach, your bean will be created once for every request the users can do in your view.

Plus, don't forget to set the ajaxOnly attribute to true if you just want to keep your bean alive for the ajax requests.

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