English 中文(简体)
richfaces keepAlive not working
原标题:

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
}
最佳回答

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.

问题回答

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...





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签