Skip to content

portlet global session ignored by by JSF request wrapper [SPR-5637] #10308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Mar 30, 2009 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 30, 2009

Alexandre Clement opened SPR-5637 and commented

the FacesRequestAttributes getAttributeMap() function doesn't handle the SCOPE_GLOBAL_SESSION.

protected Map getAttributeMap(int scope) {
		if (scope == SCOPE_REQUEST) {
			return getExternalContext().getRequestMap();
		}
		else {
			return getExternalContext().getSessionMap();
		}
	}

I had to access to the underlying portletsession to manage it. I didn't find a way to do it without declaring a dependency on the portlet-api.

protected Map getAttributeMap(int scope) {
		if (scope == SCOPE_REQUEST) {
			return getExternalContext().getRequestMap();
		}
		else if (scope == SCOPE_SESSION) {
			return getExternalContext().getSessionMap();
		} else {
		    Object session = getExternalContext().getSession(true);
		    if (session instanceof PortletSession) {
		        return ((PortletSession)session).getAttributeMap(PortletSession.APPLICATION_SCOPE);
		    } else {
		        return getExternalContext().getSessionMap();
		    }
		}
	}

Sub-tasks:

Referenced from: commits 2524ca3

@spring-projects-issues
Copy link
Collaborator Author

Alexandre Clement commented

Be careful, ((PortletSession) session).getAttributeMap() returns an immutable map while externalContext.getSessionMap() returns a mutable map.

public static Map<String, Object> getGlobalSessionMapIfPossible(ExternalContext externalContext) {
 	                        Object session = externalContext.getSession(true);
 	                        if (session instanceof PortletSession) {
 	                                return ((PortletSession) session).getAttributeMap(PortletSession.APPLICATION_SCOPE);
 	                        }
	                        else {
 	                                return externalContext.getSessionMap();
 	                        }
	                }

Potential undesired side effects when adding elements to the map:

public void setAttribute(String name, Object value, int scope) {
		getAttributeMap(scope).put(name, value);
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants