Setting non-serializable attribute value into HttpSession

4.2k views Asked by At

I get an error sometimes when I deployed project, but does not it every time. Localbean does not work when the error

error message

Warning:   JSF1063: WARNING! Setting non-serializable attribute value into HttpSession (key: localBean, value class: LocalBean).

Localbean

package com.mycompany.crm;

import java.io.Serializable;
import java.util.Locale;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped

public class LocalBean implements Serializable{
    public Locale locale;

    @PostConstruct
    public void init() {
        locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
    }

    public Locale getLocale() {
        return locale;
    }

    public String getLanguage() {
        return locale.getLanguage();
    }

    public void setLanguage(String language) {
        locale = new Locale(language);
        FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
    }
}
1

There are 1 answers

3
guilhebl On

try placing a serialVersionUID field in your class like:

private static final long serialVersionUID = -1;