richfaces keepAlive 不起作用

发布于 2024-08-21 18:59:01 字数 739 浏览 7 评论 0原文

我有一个 mediaOutput 标签,在其 createContent 属性中,要求支持 bean 处于某种状态。填充在 init 方法中的值列表必须可用。

因此,我为整个支持 bean 添加了一个 keepAlive 标签。我现在确实看到了 backingBean 而不是一些(richfaces)代理 bean,但是填充的列表再次为空。

如何使这成为可能?

我检查了 init 方法是否被调用,并且列表是否已填充在 init 方法中。

<a4j:keepAlive beanName="myBean" />
<a4j:mediaOutput createContent="#{myBean.writeChart}" ... />

支撑豆

public class MyBean implements Serializable {

public List list;

public void init(ActionEvent event) {
   // call some resource to fill the list
   list = service.getItems();
}

public void writeChart(final OutputStream out, final Object data) throws IOException {
   // list is null
}

// getters & setters
}

I have a mediaOutput tag which, in its createContent attribute, requires the backing bean to be in a certain state. A list of values, which is filled in an init method, must be available.

I therefore added a keepAlive tag for the whole backing bean. I now indeed see the backingBean in stead of some (richfaces) proxy bean, but the filled list is null again.

How to make this possible?

I checked that the init method was called and that the list is filled in in the init method.

<a4j:keepAlive beanName="myBean" />
<a4j:mediaOutput createContent="#{myBean.writeChart}" ... />

The backing bean

public class MyBean implements Serializable {

public List list;

public void init(ActionEvent event) {
   // call some resource to fill the list
   list = service.getItems();
}

public void writeChart(final OutputStream out, final Object data) throws IOException {
   // list is null
}

// getters & setters
}

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

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

发布评论

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

评论(2

舞袖。长 2024-08-28 18:59:01

声明您的 bean 在 session 范围内。

如果 bean 中有其他仅请求信息,则只需创建一个新的请求范围 bean 并将所有其他内容移至那里。它完全清晰易读。

Declare your bean to be in session scope.

If you have other request-only information in the bean, then just create a new request-scoped bean and move all the other stuff there. It's perfectly legible.

荒岛晴空 2024-08-28 18:59:01

这不是问题。您不必让 Mediabean 保持活动状态,而且您也不能。 createContent 参数中给出的 bean 将由 MediaOutput 组件创建。 “bean”前缀是令人不安的——这只是一个简单的java类,其中包含paint(...)方法。您必须在这个简单的“bean”中将 keepalived bean(例如支持 bean)作为 ManagedProperty 获取,并且它也可以包含 keepalived 信息。

示例:

带有 @ManagedBean(name = "ABCBean") 和 @RequestScoped 注释的 abc.xhtml 和 ABC.java。
您将 ABCBean 用作 abc.xhtml 的支持 Bean,但不在 mediaOutput.createContent 参数中!但是您可以使用 @ManagedBean(name="MediaBean") 注释创建 MediaBean.java,它有一个 @ManagedProperty,它获取 MediaBean 中的 ABCBean 实例。并且 ABCBean 实例保持活动状态...

This is not a problem. You don't have to keep the Mediabean alive, and you can't. The bean which is given in the createContent parameter will be created by the MediaOutput component. The "bean" prefix is the disturbing one - this is only a simple java class which contains the paint(...) method. You have to get the keepalived bean (for example a backing bean) in this simple "bean" as a ManagedProperty, and it can contain the keepalived information too.

Example:

abc.xhtml and ABC.java with @ManagedBean(name = "ABCBean") and @RequestScoped annotation.
You use ABCBean as a Backing Bean with the abc.xhtml, but NOT in the mediaOutput.createContent parameter! But you can create MediaBean.java with @ManagedBean(name="MediaBean") annotation, and it has a @ManagedProperty which gets the ABCBean instance in the MediaBean. And the ABCBean instance is keepalived...

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