[jboss-user] [JBoss Seam] - How can I get the session id?
chicochen
do-not-reply at jboss.com
Fri Jan 4 22:25:20 EST 2008
I use below code, but FacesContext.getCurrentInstance() always return null.
| FacesContext facesContext = FacesContext.getCurrentInstance();
| ExternalContext externalContext = facesContext.getExternalContext();
| HttpSession session = (HttpSession)externalContext.getSession(true);
| String sessionId = session.getId();
package com.eastidea.menglishweb.action;
|
| import javax.faces.context.ExternalContext;
| import javax.faces.context.FacesContext;
| import javax.persistence.EntityManager;
| import javax.persistence.NoResultException;
| import javax.servlet.http.HttpSession;
|
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.security.Identity;
|
| import com.eastidea.menglishweb.action.base.BaseActionImpl;
| import com.eastidea.menglishweb.entity.User;
|
| @Name("authenticateAction")
| public class AuthenticateActionImpl extends BaseActionImpl implements
| AuthenticateAction {
|
| private static final long serialVersionUID = 7601102159656515184L;
|
| @In
| private EntityManager entityManager;
|
| @In
| private Identity identity;
|
| public boolean authenticate() {
| try {
| User user = (User) entityManager
| .createQuery(
| "from User where username = :username and password = :password")
| .setParameter("username", identity.getUsername())
| .setParameter("password", identity.getPassword())
| .getSingleResult();
| setCurrentUser(user);
|
| FacesContext facesContext = FacesContext.getCurrentInstance();
| ExternalContext externalContext = facesContext.getExternalContext();
| HttpSession session = (HttpSession)externalContext.getSession(true);
| String sessionId = session.getId();
|
| return true;
| } catch (NoResultException ex) {
| return false;
| }
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117251#4117251
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117251
More information about the jboss-user
mailing list