Example usage for javax.servlet.jsp PageContext findAttribute

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

Introduction

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

Prototype


abstract public Object findAttribute(String name);

Source Link

Document

Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null.

Usage

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);
        }/*  w w  w .j  a v a 2 s  . 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:jp.terasoluna.fw.web.taglib.TagUtil.java

/**
 * wBeanwXR?[v?B/*from   w  w w. j a v a  2 s .  c  om*/
 * ?scopeNameNull??PageScope?B
 * 
 * @param pageContext y?[WReLXg
 * @param name Bean
 * @param scopeName BeanXR?[v
 * @return Bean
 * @throws JspException vXR?[v???
 */
public static Object lookup(PageContext pageContext, String name, String scopeName) throws JspException {

    if (scopeName == null) {
        return pageContext.findAttribute(name);
    }

    return pageContext.getAttribute(name, getScope(scopeName));

}

From source file:com.googlecode.jtiger.modules.ecside.util.ExtremeUtils.java

/**
 * Get the bean out of the proper scope.
 *///w w  w .jav a  2s .c  o m
public static Object retrieveFromScope(PageContext pageContext, String name, String scope) {
    if (StringUtils.isBlank(scope)) {
        return pageContext.findAttribute(name);
    }

    int scopeType = PageContext.REQUEST_SCOPE;

    if (scope.equalsIgnoreCase("page")) {
        scopeType = PageContext.PAGE_SCOPE;
    } else if (scope.equalsIgnoreCase("application")) {
        scopeType = PageContext.APPLICATION_SCOPE;
    } else if (scope.equalsIgnoreCase("session")) {
        scopeType = PageContext.SESSION_SCOPE;
    }

    return pageContext.getAttribute(name, scopeType);
}

From source file:de.iteratec.iteraplan.presentation.tags.TagUtils.java

/**
 * Locate and return the specified bean, from an optionally specified scope, in the specified page
 * context. If no such bean is found, return <code>null</code> instead.
 * //from w ww  . j  a  va  2 s . co  m
 * @param pageContext
 *          Page context to be searched
 * @param name
 *          Name of the bean to be retrieved
 * @param scopeName
 *          Scope to be searched (page, request, session, application) or <code>null</code> to use
 *          <code>findAttribute()</code> instead
 * @return JavaBean in the specified page context
 * @throws JspException
 *           if an invalid scope name is requested
 */
public static Object lookup(PageContext pageContext, String name, String scopeName) throws JspException {

    if (scopeName == null) {
        return pageContext.findAttribute(name);
    }

    return pageContext.getAttribute(name, getScope(scopeName));
}

From source file:net.sourceforge.vulcan.web.JstlFunctions.java

public static List<String> getAvailableDashboardColumns(PageContext pageContext) {
    final List<String> availableColumns = getAllDashboardColumns(Keys.DASHBOARD_COLUMNS);

    availableColumns.addAll(getAvailableMetrics());

    final PreferencesDto prefs = (PreferencesDto) pageContext.findAttribute(Keys.PREFERENCES);

    if (prefs != null && prefs.getDashboardColumns() != null) {
        // Start with the chosen columns in the chosen order.
        final List<String> userSorted = new ArrayList<String>(Arrays.asList(prefs.getDashboardColumns()));

        // Remove any columns that are no longer valid.
        userSorted.retainAll(availableColumns);

        // Remove duplicates from set of unselected columns.
        availableColumns.removeAll(userSorted);

        // Add the unselected columns to the end of the list.
        userSorted.addAll(availableColumns);

        return userSorted;
    }//  w  w w.  j a v  a2  s. com

    return availableColumns;
}

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

public static void addMessage(PageContext context, String key, String messageKey, Object... args) {
    if (context == null || key == null) {
        throw new IllegalArgumentException(
                "context (" + context + ") and key (" + key + ") must both not be null");
    }/*w w w  .j  a v  a 2 s  . co m*/
    if (messageKey != null && !"".equals(messageKey)) {
        // get the message from messageSource if possible
        MessageSource ms = (MessageSource) context.findAttribute("messageSource");
        Locale locale = context.getRequest().getLocale();
        String message;
        try {
            message = ms.getMessage(messageKey, args, locale);
        } catch (NoSuchMessageException e) {
            message = "{{INVALID KEY:" + messageKey + "}}";
        }
        addMessage(context, key, message);
    }
}

From source file:freemarker.ext.jsp._FreeMarkerPageContext2.java

/**
 * Returns a variable resolver that will resolve variables by searching through
 * the page scope, request scope, session scope and application scope for an
 * attribute with a matching name.//  ww  w  .ja  va  2  s . com
 */
public VariableResolver getVariableResolver() {
    final PageContext ctx = this;

    return new VariableResolver() {
        public Object resolveVariable(String name) throws ELException {
            return ctx.findAttribute(name);
        }
    };
}

From source file:freemarker.ext.jsp._FreeMarkerPageContext21.java

/**
 * Returns a variable resolver that will resolve variables by searching through
 * the page scope, request scope, session scope and application scope for an
 * attribute with a matching name.// ww w .jav  a 2 s. c o  m
 */
@Override
public VariableResolver getVariableResolver() {
    final PageContext ctx = this;

    return new VariableResolver() {
        public Object resolveVariable(String name) throws ELException {
            return ctx.findAttribute(name);
        }
    };
}

From source file:com.feilong.taglib.util.TagUtils.java

/**
 * Locate and return the specified bean, from an optionally specified scope, in the specified page context. If no such bean is found,
 * return <code>null</code> instead. If an exception is thrown, it will have already been saved via a call to
 * <code>saveException()</code>.
 * //  ww  w.j  a  v a  2 s.c o  m
 * @param pageContext
 *            Page context to be searched
 * @param name
 *            Name of the bean to be retrieved
 * @param scopeName
 *            Scope to be searched (page, request, session, application) or <code>null</code> to use <code>findAttribute()</code>
 *            instead
 * @return JavaBean in the specified page context
 * @throws JspException
 *             if an invalid scope name is requested
 */
public Object lookup(PageContext pageContext, String name, String scopeName) throws JspException {
    if (scopeName == null) {
        return pageContext.findAttribute(name);
    }
    try {
        return pageContext.getAttribute(name, instance.getScope(scopeName));
    } catch (JspException e) {
        throw e;
    }
}

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

/**
 * Locate and return the specified bean, from an optionally specified scope,
 * in the specified page context. If no such bean is found, return
 * <code>null</code> instead. If an exception is thrown, it will have
 * already been saved via a call to <code>saveException()</code>.
 * /*from   www.  j ava 2  s  .  c o m*/
 * @param pageContext
 *            Page context to be searched
 * @param name
 *            Name of the bean to be retrieved
 * @param scopeName
 *            Scope to be searched (page, request, session, application) or
 *            <code>null</code> to use <code>findAttribute()</code> instead
 * @return JavaBean in the specified page context
 * @throws JspException
 *             if an invalid scope name is requested
 */
public Object lookup(PageContext pageContext, String name, String scopeName) throws JspException {
    if (scopeName == null) {
        return pageContext.findAttribute(name);
    }

    try {
        return pageContext.getAttribute(name, instance.getScope(scopeName));
    } catch (JspException e) {
        saveException(pageContext, e);
        throw e;
    }
}