webtier@glassfish.java.net

Spring 3 and JSF2 Scopes

From: Lincoln Baxter, III <lincolnbaxter_at_gmail.com>
Date: Tue, 20 Oct 2009 17:49:48 -0400

Has anyone had any success getting Spring to register the new JSF
scopes? Any tips on how this might be done?

I've been getting NotSerializableExceptions whenever I attempt to put a
bean into the Flash / View scopes through spring. My beans don't seem to
require serialization for Session scope.... why would this be different
for View or Flash?

Thanks!




public class FlashScope implements Scope
{
        @Override
        public Object get(final String name, final ObjectFactory<?>
objectFactory)
        {
                Object object =
FacesContext.getCurrentInstance().getExternalContext().getFlash().get(name);
                if (object == null)
                {
                        object = objectFactory.getObject();

FacesContext.getCurrentInstance().getExternalContext().getFlash().put(name, object);
                }
                return object;
        }

        @Override
        public String getConversationId()
        {
                return null;
        }

        @Override
        public void registerDestructionCallback(final String name, final
Runnable callback)
        {}

        @Override
        public Object remove(final String name)
        {
                return
FacesContext.getCurrentInstance().getExternalContext().getFlash().remove(name);
        }

        @Override
        public Object resolveContextualObject(final String key)
        {
                return
FacesContext.getCurrentInstance().getExternalContext().getFlash();
        }
}














--
Lincoln Baxter, III
Co-Founder of OcpSoft
Creator of:
PrettyFaces: URL rewriting for JSF
PrettyTime: Java elapsed timestamp formatting