将不可序列化的属性值设置为HttpSession

时间:2014-11-13 22:21:22

标签: java jsf glassfish-4 serializable httpsession

有时我在部署项目时遇到错误,但每次都没有。错误

时,Localbean不起作用

错误消息

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 个答案:

答案 0 :(得分:0)

尝试在您的类中放置serialVersionUID字段,如:

private static final long serialVersionUID = -1;