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开发者_StackOverflow 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...
精彩评论