Assume I have a session scoped bean with object references in it, where the bean extends from an abstract generic base class. Example:
public abstract class AbstractCrudController<K, E> implements Serializable {
private Class<E> entityClass;
private E user;
public E getUser() {
if (user == null) {
try {
user = entityClass.newInstance();
} catch (Exception ex) {
JsfUtil.addErrorMessage(ex, JsfUtil.getStringResource("fatalError"));
return null;
}
}
return user;
}
public AbstractCrudController(Class<E> entityClass) {
this.entityClass = entityClass;
}
}
@ManagedBean
@SessionScoped
public class UserController extends AbstractCrudController<String, User> implements Serializable {
public UserController() {
super(User.class);
}
}
And I'm accessing the properties of user in JSF via EL, like so:
<h:inputText id="firstName" title="#{str.firstName}"
value="#{userController.user.firstName}" >
<f:ajax render="outputText"/>
</h:inputText>
<h:outputText id="outputText" value="Hello World" rendered="#{not empty userController.user.firstName}" />
What I observed is in the debugger is that the user object does not remain alive across the ajax request. I.e. when the outputText is rendered, the user is null. I found out that this is because the user is a generic type. When I make the user instance variable of type User in the base class, everything works. But I have no explanation for this.
Any idea? Thank, Theo