3

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);
    }
}
Leo
  • 6,480
  • 4
  • 37
  • 52
SerefSEVEN
  • 45
  • 3
  • 11

1 Answers1

0

try placing a serialVersionUID field in your class like:

private static final long serialVersionUID = -1;
guilhebl
  • 8,330
  • 10
  • 47
  • 66
  • Your class seems to be ok, it should be serializable, is there anything else in the logs that shows an Exception? Is LocalBean a property in some other class? – guilhebl Nov 19 '14 at 03:09
  • There is also such an error message, JSF1074: Managed bean named 'localBean' has already been registered. Replacing existing managed bean class type com.mycompany.crm.LocalBean with LocalBean. – SerefSEVEN Nov 19 '14 at 16:43
  • perhaps you're mapping your bean twice, try searching on your code for another bean named localBean or change your bean name like @ManagedBean(name="myLocalBean") – guilhebl Nov 19 '14 at 18:09