Example usage for javax.servlet.jsp PageContext PAGE_SCOPE

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

Introduction

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

Prototype

int PAGE_SCOPE

To view the source code for javax.servlet.jsp PageContext PAGE_SCOPE.

Click Source Link

Document

Page scope: (this is the default) the named reference remains available in this PageContext until the return from the current Servlet.service() invocation.

Usage

From source file:org.jboss.dashboard.ui.taglib.DefineObjectsTag.java

/**
 * Processes the <CODE>defineObjects</CODE> tag.
 *
 * @return <CODE>SKIP_BODY</CODE>
 *//*from  w w w. jav  a  2s .c om*/
public int doStartTag() throws JspException {

    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

    // Current panel (passed as a parameter through the request)
    Panel currentPanel = null;
    try {
        currentPanel = (Panel) request.getAttribute(Parameters.RENDER_PANEL);
        if (currentPanel == null) {
            log.error("Current context values are: ");
            log.error("request.ATTRIBUTE_SECTION_ID = " + request.getAttribute("current_section_id"));
            log.error("session.ATTRIBUTE_SECTION_ID = "
                    + request.getSession().getAttribute("current_section_id"));
            log.error("request.ATTRIBUTE_WORKSPACE_ID = " + request.getAttribute("current_workspace_id"));
            log.error("session.ATTRIBUTE_WORKSPACE_ID = "
                    + request.getSession().getAttribute("current_workspace_id"));
            Section currentSectionValue = NavigationManager.lookup().getCurrentSection();
            Workspace currentWorkspaceValue = NavigationManager.lookup().getCurrentWorkspace();
            log.error("Current section = " + currentSectionValue == null ? "null"
                    : currentSectionValue.getId().toString());
            log.error("Current workspace = " + currentWorkspaceValue == null ? "null"
                    : currentWorkspaceValue.getId());
            throw new JspException("The panel is not present in the workspace response"); // Don't render
        }
    } catch (Exception e) {
        throw new JspException("The panel is not present in the workspace response"); // Don't render
    }

    // Retrieve current section from session
    Section currentSection = currentPanel.getSection();
    if (currentSection == null)
        throw new JspException("The section is not present in the workspace response"); // Don't render

    // Current workspace
    WorkspaceImpl currentWorkspace = currentSection.getWorkspace();

    PanelSession panelSession = SessionManager.getPanelSession(currentPanel);

    // Provider
    PanelProvider panelProvider = currentPanel.getInstance().getProvider();

    // Panel Driver
    PanelDriver panelDriver = panelProvider.getDriver();
    Locale currentLocale = LocaleManager.currentLocale();

    if (pageContext.getAttribute("currentSection") == null)
        pageContext.setAttribute("currentSection", currentSection, PageContext.PAGE_SCOPE);

    if (pageContext.getAttribute("currentWorkspace") == null)
        pageContext.setAttribute("currentWorkspace", currentWorkspace, PageContext.PAGE_SCOPE);

    if (pageContext.getAttribute("currentPanel") == null)
        pageContext.setAttribute("currentPanel", currentPanel, PageContext.PAGE_SCOPE);

    if (pageContext.getAttribute("panelProvider") == null)
        pageContext.setAttribute("panelProvider", panelProvider, PageContext.PAGE_SCOPE);

    if (pageContext.getAttribute("panelDriver") == null)
        pageContext.setAttribute("panelDriver", panelDriver, PageContext.PAGE_SCOPE);

    if (pageContext.getAttribute("panelSession") == null)
        pageContext.setAttribute("panelSession", panelSession, PageContext.PAGE_SCOPE);

    if (pageContext.getAttribute("currentLocale") == null)
        pageContext.setAttribute("currentLocale", currentLocale, PageContext.PAGE_SCOPE);

    return SKIP_BODY;
}

From source file:org.jboss.dashboard.ui.taglib.PropertyReadTag.java

public int doEndTag() throws JspException {
    try {/*  w w w.  j a v  a 2 s. c om*/
        Object value = getPropertyValue();
        if (value == null) {
            log.debug("Property is null. Clearing content.");
            if (super.bodyContent != null) {
                value = super.bodyContent.getString();
                super.bodyContent.clear();
            }
        }
        if (value != null) {
            log.debug("value = " + value);
            if (super.id != null) {
                log.debug("Setting " + super.id + " to " + value);
                super.pageContext.setAttribute(super.id, value, PageContext.PAGE_SCOPE);
                return SKIP_BODY;
            } else {
                log.debug("Printing value " + value);
                super.pageContext.getOut().print(value);
            }
        }
    } catch (Exception e) {
        handleError(e);
    }
    return EVAL_PAGE;
}

From source file:org.jboss.dashboard.ui.taglib.resource.ImageResolverTag.java

@Override
public int doEndTag() throws JspException {
    try {/*from w w w .j  a  v  a 2s .c  o m*/

        if (StringUtils.isEmpty(imageURL)) {
            if (log.isDebugEnabled())
                log.debug("imageURL is null . Clearing content.");
            if (super.bodyContent != null) {
                imageURL = super.bodyContent.getString();
                super.bodyContent.clear();
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("imageURL = " + imageURL + ". ");
            if (super.id != null) {
                if (log.isDebugEnabled())
                    log.debug("Setting " + super.id + " to " + imageURL);
                super.pageContext.setAttribute(super.id, imageURL, PageContext.PAGE_SCOPE);
                return SKIP_BODY;
            } else {
                if (log.isDebugEnabled())
                    log.debug("Printing imageURL to " + imageURL);
                super.pageContext.getOut().print(imageURL);
            }
        }
    } catch (Exception e) {
        handleError(e);
    }
    return EVAL_PAGE;
}

From source file:org.jboss.dashboard.ui.taglib.ResourceLinkTag.java

public int doEndTag() throws JspException {
    try {/*from   ww w.  j a va 2 s.c o  m*/
        if (linkUrl == null) {
            log.debug("linkUrl is null (resource not found?). Clearing content.");
            if (super.bodyContent != null) {
                linkUrl = super.bodyContent.getString();
                super.bodyContent.clear();
            }
        }
        if (linkUrl != null) {
            log.debug("linkUrl = " + linkUrl + ". ");
            if (super.id != null) {
                log.debug("Setting " + super.id + " to " + linkUrl);
                super.pageContext.setAttribute(super.id, linkUrl, PageContext.PAGE_SCOPE);
                return SKIP_BODY;
            } else {
                log.debug("Printing link to " + linkUrl);
                super.pageContext.getOut().print(linkUrl);
            }
        }
    } catch (Exception ex) {
        log.error("Error: ", ex);
        throw new JspException("Exception ", ex);
    }
    return EVAL_PAGE;
}

From source file:org.jbpm.bui.taglib.ImageResolverTag.java

@Override
public int doEndTag() throws JspException {
    try {//from  www .  ja  va 2  s. c o m

        if (StringUtils.isEmpty(imageURL)) {
            if (log.isDebugEnabled())
                log.debug("imageURL is null . Clearing content.");
            if (super.bodyContent != null) {
                imageURL = super.bodyContent.getString();
                super.bodyContent.clear();
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("imageURL = " + imageURL + ". ");
            if (super.id != null) {
                if (log.isDebugEnabled())
                    log.debug("Setting " + super.id + " to " + imageURL);
                super.pageContext.setAttribute(super.id, imageURL, PageContext.PAGE_SCOPE);
                return SKIP_BODY;
            } else {
                if (log.isDebugEnabled())
                    log.debug("Printing imageURL to " + imageURL);
                super.pageContext.getOut().print(imageURL);
            }
        }
    } catch (Exception ex) {
        log.error("Error building imageURL: ", ex);
        throw new JspException("Exception ", ex);
    }
    return EVAL_PAGE;
}

From source file:org.musicrecital.webapp.taglib.ConstantsTag.java

/**
 * Main method that does processing and exposes Constants in specified scope 
 * @return int/* ww w  . j  av  a  2 s. c  o m*/
 * @throws JspException if processing fails
 */
@Override
public int doStartTag() throws JspException {
    // Using reflection, get the available field names in the class
    Class c = null;
    int toScope = PageContext.PAGE_SCOPE;

    if (scope != null) {
        toScope = getScope(scope);
    }

    try {
        c = Class.forName(clazz);
    } catch (ClassNotFoundException cnf) {
        log.error("ClassNotFound - maybe a typo?");
        throw new JspException(cnf.getMessage());
    }

    try {
        // if var is null, expose all variables
        if (var == null) {
            Field[] fields = c.getDeclaredFields();

            AccessibleObject.setAccessible(fields, true);

            for (Field field : fields) {
                pageContext.setAttribute(field.getName(), field.get(this), toScope);
            }
        } else {
            try {
                Object value = c.getField(var).get(this);
                pageContext.setAttribute(c.getField(var).getName(), value, toScope);
            } catch (NoSuchFieldException nsf) {
                log.error(nsf.getMessage());
                throw new JspException(nsf);
            }
        }
    } catch (IllegalAccessException iae) {
        log.error("Illegal Access Exception - maybe a classloader issue?");
        throw new JspException(iae);
    }

    // Continue processing this page
    return (SKIP_BODY);
}

From source file:org.openhie.openempi.webapp.taglib.ConstantsTag.java

/**
 * Main method that does processing and exposes Constants in specified scope 
 * @return int//from   w  w  w .  j a  v a 2  s.  c  o  m
 * @throws JspException if processing fails
 */
@SuppressWarnings("unchecked")
@Override
public int doStartTag() throws JspException {
    // Using reflection, get the available field names in the class
    Class c = null;
    int toScope = PageContext.PAGE_SCOPE;

    if (scope != null) {
        toScope = getScope(scope);
    }

    try {
        c = Class.forName(clazz);
    } catch (ClassNotFoundException cnf) {
        log.error("ClassNotFound - maybe a typo?");
        throw new JspException(cnf.getMessage());
    }

    try {
        // if var is null, expose all variables
        if (var == null) {
            Field[] fields = c.getDeclaredFields();

            AccessibleObject.setAccessible(fields, true);

            for (Field field : fields) {
                pageContext.setAttribute(field.getName(), field.get(this), toScope);
            }
        } else {
            try {
                Object value = c.getField(var).get(this);
                pageContext.setAttribute(c.getField(var).getName(), value, toScope);
            } catch (NoSuchFieldException nsf) {
                log.error(nsf.getMessage());
                throw new JspException(nsf);
            }
        }
    } catch (IllegalAccessException iae) {
        log.error("Illegal Access Exception - maybe a classloader issue?");
        throw new JspException(iae);
    }

    // Continue processing this page
    return (SKIP_BODY);
}

From source file:org.qifu.ui.UIComponentValueUtils.java

public static Object getOgnlProcessObjectFromPageContextOrRequest(PageContext pageContext, String expression) {
    Map<String, Object> ognlRoot = new HashMap<String, Object>();
    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    Enumeration<String> pcNames = pageContext.getAttributeNamesInScope(PageContext.PAGE_SCOPE);
    Enumeration<String> pNames = request.getParameterNames();
    Enumeration<String> aNames = request.getAttributeNames();
    /**/*from  w  ww .  java  2s  . c om*/
     * ognlRoot , ?: pageContext.getAttribute > request.getParameter > request.getAttribute
     */
    while (pcNames.hasMoreElements()) {
        String key = pcNames.nextElement();
        ognlRoot.put(key, pageContext.getAttribute(key));
    }
    while (pNames.hasMoreElements()) {
        String key = pNames.nextElement();
        if (ognlRoot.get(key) == null) {
            ognlRoot.put(key, request.getParameter(key));
        }
    }
    while (aNames.hasMoreElements()) {
        String key = aNames.nextElement();
        if (ognlRoot.get(key) == null) {
            ognlRoot.put(key, request.getAttribute(key));
        }
    }
    if (ognlRoot.size() == 0) {
        ognlRoot = null;
        return null;
    }
    Object val = null;
    try {
        val = Ognl.getValue(expression, ognlRoot);
    } catch (OgnlException e) {
        //e.printStackTrace();
    }
    ognlRoot.clear();
    ognlRoot = null;
    return val;
}

From source file:org.rhq.enterprise.gui.legacy.taglib.display.TableTag.java

/**
 * This functionality is borrowed from struts, but I've removed some struts specific features so that this tag can
 * be used both in a struts application, and outside of one.
 *
 * <p/>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.
 *
 * @param  pageContext Page context to be searched
 * @param  name        Name of the bean to be retrieved
 * @param  scope       Scope to be searched (page, request, session, application) or <code>null</code> to use <code>
 *                     findAttribute()</code> instead
 *
 * @throws JspException if an invalid scope name is requested
 *///  w w w.  j  a  va 2  s .co  m

public Object lookup(PageContext pageContext, String name, String scope) throws JspException {
    log.trace("looking up: " + name + " in scope: " + scope);

    Object bean;
    if (scope == null) {
        bean = pageContext.findAttribute(name);
    } else if (scope.equalsIgnoreCase("page")) {
        bean = pageContext.getAttribute(name, PageContext.PAGE_SCOPE);
    } else if (scope.equalsIgnoreCase("request")) {
        bean = pageContext.getAttribute(name, PageContext.REQUEST_SCOPE);
    } else if (scope.equalsIgnoreCase("session")) {
        bean = pageContext.getAttribute(name, PageContext.SESSION_SCOPE);
    } else if (scope.equalsIgnoreCase("application")) {
        bean = pageContext.getAttribute(name, PageContext.APPLICATION_SCOPE);
    } else {
        Object[] objs = { name, scope };
        if (prop.getProperty("error.msg.cant_find_bean") != null) {
            String msg = MessageFormat.format(prop.getProperty("error.msg.cant_find_bean"), objs);
            throw new JspException(msg);
        } else {
            throw new JspException("Could not find " + name + " in scope " + scope);
        }
    }

    return (bean);
}

From source file:org.richfaces.taglib.ColumnsTag.java

/**
 * Sets page request variables/* w w w. ja va 2  s  . c o m*/
 * 
 * @throws JspTagException
 */
private void exposeVariables() throws JspTagException {

    /*
     * We need to support null items returned from next(); we do this simply
     * by passing such non-items through to the scoped variable as
     * effectively 'null' (that is, by calling removeAttribute()).
     * 
     * Also, just to be defensive, we handle the case of a null 'status'
     * object as well.
     * 
     * We call getCurrent() and getLoopStatus() (instead of just using
     * 'item' and 'status') to bridge to subclasses correctly. A subclass
     * can override getCurrent() or getLoopStatus() but still depend on our
     * doStartTag() and doAfterBody(), which call this method
     * (exposeVariables()), to expose 'item' and 'status' correctly.
     */

    // Set up var variable
    if (itemId != null) {
        if (index == null)
            pageContext.removeAttribute(itemId, PageContext.PAGE_SCOPE);
        else if (__value != null) {
            VariableMapper vm = pageContext.getELContext().getVariableMapper();
            if (vm != null) {
                ValueExpression ve = getVarExpression(__value);
                vm.setVariable(itemId, ve);
            }
        } else
            pageContext.setAttribute(itemId, index);
    }

    // Set up index variable

    if (indexId != null) {
        if (index == null)
            pageContext.removeAttribute(indexId, PageContext.PAGE_SCOPE);
        else {
            IteratedIndexExpression indexExpression = new IteratedIndexExpression(index);
            VariableMapper vm = pageContext.getELContext().getVariableMapper();
            if (vm != null) {
                vm.setVariable(indexId, indexExpression);
            }
        }
    }

}