I'm building a JSF application. The JSF application contains some CDI beans, which hold the session data. I want to save this session data to a file and load it at a later time.
Example 1:
@SessionScoped
MyBean implements Serializable {
private String myValue;
//getter and setters
}
@RequestScoped
MyLoadingService {
@Inject
private MyBean myBean;
public void load(byte[] data){
MyBean newMyBean = (MyBean)org.apache.commons.lang3.SerializationUtils.deserialize(data);
//this doesn't work, because myBean is a proxy here...
//how can I achieve this to work?
myBean = newMyBean;
}
}
Example 2:
A session scoped bean, which contains another bean, which should be loaded.
@SessionScoped
AnotherBean implements Serializable {
private String otherValue;
//getter and setters
}
@SessionScoped
MyBean implements Serializable {
@Inject
AnotherBean anotherBean;
private String myValue;
//getter and setters
}
@RequestScoped
MyLoadingService {
@Inject
private MyBean myBean;
public void load(byte[] data){
MyBean newMyBean = (MyBean)org.apache.commons.lang3.SerializationUtils.deserialize(data);
//this doesn't work, because myBean is a proxy here...
//how can I achieve this to work?
myBean = newMyBean;
}
}
Is this possible?