3

我创建了一个SessionListener,但它不起作用,因为我不知道如何在faces-config.xml. 我尝试了以下方法:

会话监听器

public class SessionListener implements HttpSessionListener {

@Override
public void sessionCreated(HttpSessionEvent arg0) {


    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    String param = request.getParameter("language");


    IDAdminLanguage idl = (IDAdminLanguage) JSFUtils.resolve("#{languageBean}");

    if (param != null && param.length() > 0) {
        idl.setLanguage(param);
    } else {
        idl.setLanguage("de");
    }   
}

@Override
public void sessionDestroyed(HttpSessionEvent arg0) { }

}

面孔配置

<listener>
   <listener-class>ch.idadmin.util.SessionListener</listener-class>
</listener>
4

1 回答 1

5

Yuu 需要在web.xml(而不是在 faces-config.xml 中)添加该配置

<web-app ...>
        <listener>
        <listener-class>ch.idadmin.util.SessionListener</listener-class>
    </listener>
</web-app>
于 2012-04-17T09:51:08.113 回答