views:

511

answers:

2

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
}
+2  A: 

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.

Bozho
That is, although it works, exactly what I tried to prevent... The backing bean contains other stuff for the same page, putting all of it on session scope would not be recommended. Creating a separate bean for it neihter. That is why keepAlive was introduced..
Jurgen H
yes, but perhaps mediaOutput doesn't go through the regular ajax-request mechanisms, so that's your only way. Perhaps you' like to use some conversation scope (orchestra, seam). see my update for the other bean
Bozho
Maybe yeah :)But they could have documented this + the mediaOutput tag is part of the a4j spec, weird that it does not support other a4j functionalities :(
Jurgen H
A: 

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

Phaidros