@Override public void setAttribute(String name, @Nullable Object value, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: setAttribute(name, value); break; case REQUEST_SCOPE: this.request.setAttribute(name, value); break; case SESSION_SCOPE: this.request.getSession().setAttribute(name, value); break; case APPLICATION_SCOPE: this.servletContext.setAttribute(name, value); break; default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Test public void setAttributeWithNoScopeUsesPageScope() throws Exception { ctx.setAttribute(key, value); assertEquals(value, ctx.getAttribute(key, PageContext.PAGE_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.REQUEST_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.SESSION_SCOPE)); }
@Test public void removeAttributeWithNoScopeSpecifiedRemovesValueFromAllScopes() throws Exception { ctx.setAttribute(key, value, PageContext.APPLICATION_SCOPE); ctx.removeAttribute(key); assertNull(ctx.getAttribute(key, PageContext.PAGE_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.APPLICATION_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.REQUEST_SCOPE)); assertNull(ctx.getAttribute(key, PageContext.SESSION_SCOPE)); }
@Override public void setAttribute(String name, Object value, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: setAttribute(name, value); break; case REQUEST_SCOPE: this.request.setAttribute(name, value); break; case SESSION_SCOPE: this.request.getSession().setAttribute(name, value); break; case APPLICATION_SCOPE: this.servletContext.setAttribute(name, value); break; default: throw new IllegalArgumentException("Invalid scope: " + scope); } }
@Override public void setAttribute(String name, @Nullable Object value, int scope) { Assert.notNull(name, "Attribute name must not be null"); switch (scope) { case PAGE_SCOPE: setAttribute(name, value); break; case REQUEST_SCOPE: this.request.setAttribute(name, value); break; case SESSION_SCOPE: this.request.getSession().setAttribute(name, value); break; case APPLICATION_SCOPE: this.servletContext.setAttribute(name, value); break; default: throw new IllegalArgumentException("Invalid scope: " + scope); } }