I am trying to convert a session scoped JSF managed bean to view scoped. However, when I try to access the xhtml page for this bean, then i get the following error:
java.io.NotSerializableException: foo.bar.SomeDaoClass
I have a member of a helper DAO that I use to delegate persistence related tasks within the bean. If I make this DAO class implement Serializable then other UIComponent references start causing the same errors!
The main use case is that I have a link on the click of which I open a jquery lightbox pop-up showing the xhtml page which is backed by a session bean. When the user clicks the submit button on the pop-up form, I remove the session bean programatically. The problem is if the user clicks the close button of the pop-up itself, and clicks on another link pointing to another id, then the same values are shown (being session scoped)!
I would like to use the view scope to preserve values while viewing this form in a pop-up and when the user clicks the close button of the pop-up, the values may be discarded.
I hope you've already resolved this problem, but for other people landing here, who don't want to use session scope and uses view scope as alternative, which force you to use serializable
implementation, you can use the transient
keyword next to the properties that you don't want to make serializable
, that would be very helpful if you want to call a service or dao.
example:
@ManagedBean(name="addressTableBeanExample4")
@ViewScoped
public class ExampleBean4 implements Serializable {
private static final long serialVersionUID = 1L;
// non serialazable class
private transient List<Customer> data = new ArrayList<Customer>();
private Customer selected;
}