Evan Leonard wrote:
What's the implementation of ctx.setLoginID(foundUser) look like?

I should look something like this:

getRequest().getSession().setAttribute(USER_KEY, currentUser);
It basically is exactly that. The MyActionBeanContext class (attached) does that in a way a little closer to the examples from the book.

--
John
package util;

import javax.servlet.http.HttpSession;

import net.sourceforge.stripes.action.*;
import daoimpl.*;
import model.*;

public class MyActionBeanContext extends ActionBeanContext {
        private static final String LOGINID = "loginid";
        
        public void setLoginID(Person loginid) {
                if (loginid != null) {
                        setCurrent(LOGINID, loginid.getId() );
                } else {
                        setCurrent(LOGINID, null);
                }
        }

        public Person getLoginID() {
                Integer loginId = getCurrent(LOGINID, null);
                if (loginId == null ) {return null;}
                return UserDao.getInstance().get(loginId);
        }
        
        public void logout() {
                setLoginID(null);
                
                HttpSession session = getRequest().getSession();
                if ( session != null ) {
                        session.invalidate();
                }
        }
        
        protected void setCurrent(String key, Object value) {
                getRequest().getSession().setAttribute(key, value);
        }
        
        @SuppressWarnings("unchecked")
        protected <T> T getCurrent(String key, T defaultValue) {
                T value = (T) getRequest().getSession().getAttribute(key);
                if ( value == null ) {
                        value = defaultValue;
                        setCurrent(key, value);
                }
                return value;
        }
        
}
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to