views:

56

answers:

1

Hello I'm using a ViewScoped Bean the Problem is that when call it I get the NotSerializableException.

This is the code of my Managed Bean :

@ManagedBean(name="demandesBean")
@ViewScoped
public class DemandesBean implements Serializable {
    private static final long serialVersionUID = 1L;

    @ManagedProperty(value="#{demandeService}")
    private DemandeService demandeService; //A Spring Service

    @ManagedProperty(value="#{loginBean}")
    private LoginBean loginBean;

    private DemandeVO newDemande;

    @PostConstruct
    public void initData() {
        newDemande = new DemandeVO();
    }

    public void doAjouterDemande(ActionListener event) {
        demandeService.createDemande(newDemande, loginBean.getUsername());
        newDemande = new DemandeVO();
    }

    public List<DemandeVO> getListDemande() {
        return demandeService.getAllDemandesByUser(loginBean.getUsername());
    }

    public DemandeService getDemandeService() {
        return demandeService;
    }

    public void setDemandeService(DemandeService demandeService) {
        this.demandeService = demandeService;
    }

    public LoginBean getLoginBean() {
        return loginBean;
    }

    public void setLoginBean(LoginBean loginBean) {
        this.loginBean = loginBean;
    }

    public DemandeVO getNewDemande() {
        return newDemande;
    }

    public void setNewDemande(DemandeVO newDemande) {
        this.newDemande = newDemande;
    }
}

I Recieve The following Exception :

GRAVE: Exiting serializeView - Could not serialize state: com.bull.congesJBPM.serviceImpl.DemandeServiceImpl
java.io.NotSerializableException: com.bull.congesJBPM.serviceImpl.DemandeServiceImpl

Any fix for this problem ?? Please Help !

+4  A: 

You've declared your bean to implement Serializable. This implicitly means that all of the nested bean properties are supposed to be Serializable as well. However, the in the message mentioned class is not Serializable. You have two options:

  1. Let it implement Serializable as well.

  2. Declare the property transient so that it won't be serialized. However, you need to instruct Spring somehow to reinject it after deserialization whenever applicable. I don't do Spring, but I recall that this isn't that trivial.

BalusC
@BalusC good, BalusC (+1) Just for curiosity: which javax.faces.STATE_SAVING_METHOD do you use: server or client ??? Can you point out some answers which can gives me its pros and cons ???
Arthur Ronald F D Garcia
I don't have any javax.faces.STATE_SAVING_METHOD configuration in my Web.xml. Should I use one ?
imrabti
@Arthur: the choice is purely a technical matter which depends on available server's memory and/or network bandwidth. @imrabti: it doesn't harm anything functional, it defaults to `server`.
BalusC
@BalusC Thank you!
Arthur Ronald F D Garcia