[jbossseam-issues] [JBoss JIRA] Updated: (JBSEAM-524) Lifecycle.isAttributeDirty(Object attribute) doesn't like null attributes

jarkko Lietolahti (JIRA) jira-events at jboss.com
Fri Nov 24 21:21:41 EST 2006


     [ http://jira.jboss.com/jira/browse/JBSEAM-524?page=all ]

jarkko Lietolahti updated JBSEAM-524:
-------------------------------------

    Component/s:     (was: Framework)

> Lifecycle.isAttributeDirty(Object attribute) doesn't like null attributes
> -------------------------------------------------------------------------
>
>                 Key: JBSEAM-524
>                 URL: http://jira.jboss.com/jira/browse/JBSEAM-524
>             Project: JBoss Seam
>          Issue Type: Bug
>    Affects Versions: 1.1.0.CR1
>            Reporter: jarkko Lietolahti
>            Priority: Blocker
>             Fix For: 1.1.0.CR2
>
>
> Sometimes (because of  living inside portal environment), WebSessionContext.flush fails when attribute obtained from Session (experimental session handling required for the portal env) is null, which is something that Lifecycle.isAttributeDirty(attribute) doesn't like and throws NPE.
> A simple fix is to check for null attribute values (others might require changing getNames() or WebSessionContext  /PortletSessionImpl.getAttributeNames() ):
>    public void flush() {
>       for ( String name: getNames() )
>       {
>          Object attribute = session.getAttribute(name);
>          if( attribute == null) {
>             continue;
>          }
>          
>          if ( Lifecycle.isAttributeDirty(attribute) )
>          {
>             session.setAttribute(name, attribute);
>          }
>       }      
>    }
> And the custom PortletSessionImpl which stores everything in APPLICATION_SCOPE instead of PORTLET_SCOPE
> /*
>  * JBoss, Home of Professional Open Source
>  *
>  * Distributable under LGPL license.
>  * See terms of license at gnu.org.
>  */
> package org.jboss.seam.portlet;
> import java.util.Collections;
> import java.util.Enumeration;
> import java.util.List;
> import javax.portlet.PortletSession;
> import org.apache.commons.collections.ListUtils;
> import org.jboss.seam.ScopeType;
> import org.jboss.seam.contexts.ContextAdaptor;
> /**
>  * @author <a href="mailto:theute at jboss.org">Thomas Heute </a>
>  * @version $Revision: 1.4 $
>  */
> public class PortletSessionImpl extends ContextAdaptor {
> 	private PortletSession session;
> 	public PortletSessionImpl(PortletSession session) {
> 		this.session = session;
> 	}
> 	protected String getPrefix() {
> 		return ScopeType.CONVERSATION.getPrefix() + '#';
> 	}
> 	protected int getScope(String key) {
> //		if (key.startsWith(getPrefix())) {
> //			return PortletSession.PORTLET_SCOPE;
> //		}
> //		
> 		return PortletSession.APPLICATION_SCOPE;
> 	}
> 	public Object getAttribute(String key) {
> 		int scope = getScope(key);
> 		Object o = session.getAttribute(key, scope);
> 		return o;
> 	}
> 	public void removeAttribute(String key) {
> 		int scope = getScope(key);
> 		session.removeAttribute(key, scope);
> 	}
> 	public void setAttribute(String key, Object value) {
> 		int scope = getScope(key);
> 		session.setAttribute(key, value, scope);
> 	}
> 	public Enumeration getAttributeNames() {
> //		if (1 == 1) {
> //			Enumeration portletAttributeNamesEnumOnly = session
> //					.getAttributeNames();
> //			Enumeration koje = session
> //					.getAttributeNames(PortletSession.APPLICATION_SCOPE);
> //			return koje;
> //		}
> 		Enumeration portletAttributeNamesEnum = session.getAttributeNames();
> 		Enumeration portalAttributeNamesEnum = session
> 				.getAttributeNames(PortletSession.APPLICATION_SCOPE);
> 		List portletAttributeNames = Collections
> 				.list(portletAttributeNamesEnum);
> 		List portalAttributeNames = Collections.list(portalAttributeNamesEnum);
> 		// TODO: Is this correct?
> 		List allNames = ListUtils.sum(portletAttributeNames,
> 				portalAttributeNames);
> 		return Collections.enumeration(allNames);
> 	}
> 	public void invalidate() {
> 		session.invalidate();
> 	}
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the seam-issues mailing list