Example usage for javax.servlet.jsp PageContext setAttribute

List of usage examples for javax.servlet.jsp PageContext setAttribute

Introduction

In this page you can find the example usage for javax.servlet.jsp PageContext setAttribute.

Prototype


abstract public void setAttribute(String name, Object value, int scope);

Source Link

Document

Register the name and value specified with appropriate scope semantics.

Usage

From source file:net.ontopia.topicmaps.db2tm.Utils.java

/**
 * INTERNAL: Helper method for maintaining a relation mapping
 * instance throughout a page context./*from   ww  w  . java 2s.co  m*/
 */
public static RelationMapping getRelationMapping(PageContext ctxt) {
    RelationMapping db = (RelationMapping) ctxt.getAttribute("RelationMapping", PageContext.APPLICATION_SCOPE);
    if (db == null) {
        db = new RelationMapping();
        ctxt.setAttribute("RelationMapping", db, PageContext.APPLICATION_SCOPE);
    }
    return db;
}

From source file:com.tonbeller.wcf.expr.ExprUtils.java

public static ExprContext getExprContextAdapter(final PageContext pageContext) {
    return new ExprContext() {
        public Object findBean(String name) {
            return pageContext.findAttribute(name);
        }/*from   w  w  w . j av  a2s  .c om*/

        public void setBean(String name, Object bean) {
            if (bean == null)
                pageContext.removeAttribute(name);
            else
                pageContext.setAttribute(name, bean, PageContext.SESSION_SCOPE);
        }
    };
}

From source file:net.ontopia.topicmaps.webed.impl.utils.TagUtils.java

/**
 * Sets the name of the action group (an attribute is set in the
 * page scope).//from w  w  w  . ja  v a  2  s . c om
 */
public static void setActionGroup(PageContext pageContext, String actionGroup) {
    pageContext.setAttribute(Constants.RA_ACTIONGROUP, actionGroup, PageContext.REQUEST_SCOPE);
}

From source file:net.ontopia.topicmaps.nav2.utils.FrameworkUtils.java

/**
 * INTERNAL: Reset MVS settings in user object in session scope.
 *//*ww w  . j  av  a 2 s .  com*/
public static void resetMVSsettingsInUserSession(PageContext pageContext) {
    NavigatorConfigurationIF navConf = NavigatorUtils.getNavigatorApplication(pageContext).getConfiguration();

    //! UserIF user = (UserIF) pageContext.getAttribute(NavigatorApplicationIF.USER_KEY,
    //!                                                 PageContext.SESSION_SCOPE);
    UserIF user = getUser(pageContext, false);
    if (user == null)
        return; // ignore if no user

    // reset MVS settings
    user = setDefaultMVS(navConf, user);
    // set user object to session scope (TODO: support other contexts?)
    pageContext.setAttribute(NavigatorApplicationIF.USER_KEY, user, PageContext.SESSION_SCOPE);
    log.info("MVS settings in user session has been reset.");
}

From source file:net.ontopia.topicmaps.nav2.utils.FrameworkUtils.java

/**
 * INTERNAL: Create new user object in given scope.
 */// ww w  .  j  ava 2 s  .c o m
public static UserIF createUserSession(PageContext pageContext, int scope) {

    NavigatorConfigurationIF navConf = NavigatorUtils.getNavigatorApplication(pageContext).getConfiguration();
    // try to retrieve the user name from the request, otherwise null
    String username = null;
    if (pageContext.getRequest() instanceof HttpServletRequest)
        username = ((HttpServletRequest) pageContext.getRequest()).getRemoteUser();
    // create new user object
    UserIF user = new User(username, navConf);
    // set MVS settings
    user = setDefaultMVS(navConf, user);
    // set user object to session scope
    pageContext.setAttribute(NavigatorApplicationIF.USER_KEY, user, scope);
    log.debug("New user object ('" + user.getId() + "') created and bound in scope ( " + scope + ").");
    return user;
}

From source file:org.sakaiproject.iclicker.tool.ToolController.java

@SuppressWarnings("unchecked")
public static void addMessage(PageContext context, String key, String message) {
    if (context == null || key == null) {
        throw new IllegalArgumentException(
                "context (" + context + ") and key (" + key + ") must both not be null");
    }//from  www  . j av  a2s.  c o  m
    if (message != null && !"".equals(message)) {
        String keyVal = ICLICKER_MESSAGES + key;
        if (context.getAttribute(keyVal) == null) {
            context.setAttribute(keyVal, new Vector<String>(), PageContext.REQUEST_SCOPE);
        }
        List<String> l = (List<String>) context.getAttribute(keyVal, PageContext.REQUEST_SCOPE);
        l.add(message);
    }
}

From source file:org.lightadmin.core.view.editor.JspFragmentFieldControl.java

protected void addAttribute(String name, Object value) {
    PageContext pageContext = (PageContext) getJspContext();
    pageContext.setAttribute(name, value, REQUEST_SCOPE);
}

From source file:com.cognifide.slice.api.tag.SliceLookupTag.java

@Override
public void doTag() throws JspException {
    try {// w w  w  .  j  ava2 s .c o  m
        if (StringUtils.isBlank(var) || (type == null)) {
            return;
        }

        final PageContext pageContext = (PageContext) getJspContext();
        final Object model = SliceTagUtils.getFromCurrentPath(pageContext, type, appName);
        pageContext.setAttribute(var, model, PageContext.PAGE_SCOPE);
    } finally {
        clean();
    }
}

From source file:de.hybris.platform.addonsupport.renderer.impl.DefaultAddOnCMSComponentRenderer.java

protected Map<String, Object> exposeVariables(final PageContext pageContext,
        @SuppressWarnings("unused") final C component) {
    final Map<String, Object> variables = getVariablesToExpose(pageContext, component);
    if (variables != null) {
        for (final Entry<String, Object> entry : variables.entrySet()) {
            pageContext.setAttribute(entry.getKey(), entry.getValue(), getScopeForVariableName(entry.getKey()));
        }/*from ww  w  . j  a va  2  s . c o  m*/
    }
    return variables;
}

From source file:com.glaf.core.tag.TagUtils.java

/**
 * Save the specified exception as a request attribute for later use.
 * //  w  ww.  j  a  v  a2 s . c o m
 * @param pageContext
 *            The PageContext for the current page
 * @param exception
 *            The exception to be saved
 */
public void saveException(PageContext pageContext, Throwable exception) {
    pageContext.setAttribute(Globals.EXCEPTION_KEY, exception, PageContext.REQUEST_SCOPE);
}