Scopes
Scopes
 

Quick start

Use with servlet requests

After succesfully installing Scopes in your web application (see installation page), you can access the State object anywhere a ServletRequest is. For example, if you want to use the State object inside a servlet, you can call:

State state = RequestUtils.getState(request);
String value = (String) state.getAttribute("session", "userName");
state.setAttribute("request", "userBean", new UserBean(userName));

Obviously, if you configured your web application to use "window" scope, you can use it by calling:

String value2 = (String) state.getAttribute("window", "windowVariable");
state.setAttribute("window", "windowVariable2", new Integer(15));

Use inside JSPs

You can access beans inside JSP through the use of <scopes:copy> tag, to copy a custom-scoped bean to a "classic" scope. Include the following line in the top of your JSP page:

<%@taglib prefix="scopes" uri="/WEB-INF/scopes-core.tld" %>

Then copy your bean this way:

<scopes:copy name="attrib" fromScope="click" />

This way the "attrib" bean is copied from "click" scope to "page" scope.