[jboss-user] [JBoss Seam] - Re: Strange Seam Actor component problem
m.makowski
do-not-reply at jboss.com
Wed Jan 17 03:24:08 EST 2007
Thanks for the reply. I used LoginAction from the dvd store example which also uses stateless bean, provides the same functionality and does work. Could you please explain what's the difference?
| package com.jboss.dvd.seam;
|
| import java.io.Serializable;
|
| import javax.ejb.Stateless;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| import org.jboss.seam.Seam;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.contexts.Context;
| import org.jboss.seam.core.Actor;
| import org.jboss.seam.core.FacesMessages;
|
| @Stateless
| @Name("login")
| public class LoginAction
| implements Login,
| Serializable
| {
| private static final String USER_VAR = "currentUser";
|
| @PersistenceContext
| private EntityManager em;
|
| @In Context sessionContext;
|
| @In Actor actor;
|
| String username = "";
| String password = "";
|
| public String getUserName() {
| return username;
| }
| public void setUserName(String username) {
| this.username = username;
| }
|
| public String getPassword() {
| return password;
| }
| public void setPassword(String password) {
| this.password = password;
| }
|
| public String login() {
| try {
| User found =
| (User) em.createQuery("select u from User u where u.userName = :userName and u.password = :password")
| .setParameter("userName", username)
| .setParameter("password", password)
| .getSingleResult();
|
| sessionContext.set(USER_VAR, found);
|
| actor.setId(username);
|
| if (found instanceof Admin) {
| actor.getGroupActorIds().add("shippers");
| actor.getGroupActorIds().add("reviewers");
| System.out.println("ADMIN");
| return "admin";
| } else {
| return null; // redisplay the current page
| }
| } catch (Exception e) {
| // this message is lost in the session invalidation
| FacesMessages.instance().addFromResourceBundle("loginErrorPrompt");
| Seam.invalidateSession();
| return "home";
| }
| }
|
| public String logout() {
| Seam.invalidateSession();
| sessionContext.set(USER_VAR, null);
| sessionContext.set("loggedIn", null);
| return "logout";
| }
|
| private User currentUser() {
| return (User) sessionContext.get(USER_VAR);
| }
|
| public boolean isLoggedIn() {
| return currentUser() != null;
| }
|
| public boolean isCustomer() {
| User user = currentUser();
| return (user!=null) && (user instanceof Customer);
| }
|
| public boolean isAdmin() {
| User user = currentUser();
| return (user!=null) && (user instanceof Admin);
| }
|
| public String adminCheck() {
| if(isAdmin())
| {
| return null;
| }
| return "home";
|
|
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4002633#4002633
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4002633
More information about the jboss-user
mailing list