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:info.magnolia.cms.taglibs.util.StrToObj.java

/**
 * @see javax.servlet.jsp.tagext.Tag#doEndTag()
 *//*  www . j  a va  2s .com*/
public int doEndTag() {
    String str = getBodyContent().getString();
    if (StringUtils.isNotEmpty(str)) {
        String[] obj = str.split(StringUtils.defaultString(this.delims, "\n")); //$NON-NLS-1$
        pageContext.setAttribute(this.var, obj, PageContext.PAGE_SCOPE);

    } else {
        pageContext.setAttribute(this.var, StringUtils.EMPTY, PageContext.PAGE_SCOPE);
    }
    return EVAL_PAGE;
}

From source file:com.cognifide.slice.cq.taglib.CatchTag.java

/** {@inheritDoc} */
@Override//from  w  w  w  .j  a  v  a 2  s  .c o  m
public int doStartTag() {
    // in case previous instance set a throwable under the same name
    if (StringUtils.isNotBlank(throwableVariableName)) {
        pageContext.removeAttribute(throwableVariableName, PageContext.PAGE_SCOPE);
    }
    return EVAL_BODY_INCLUDE;
}

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

@Override
public void doTag() throws JspException {
    try {//ww  w. ja v a  2 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:cherry.foundation.code.CodeTagSupport.java

@Override
protected int doStartTagInternal() throws Exception {
    CodeManager codeManager = getCodeManager();
    T object = getObject(codeManager, codeName, value, plainLabel);
    if (StringUtils.isNotEmpty(var)) {
        VariableMapper vm = pageContext.getELContext().getVariableMapper();
        if (vm != null) {
            vm.setVariable(var, null);
        }// ww  w.j  a v  a 2s . c  om
        pageContext.setAttribute(var, object, PageContext.PAGE_SCOPE);
    }
    if (doesEvalBody(codeManager, codeName, value, plainLabel)) {
        return EVAL_BODY_INCLUDE;
    } else {
        return SKIP_BODY;
    }
}

From source file:com.cognifide.slice.cq.taglib.CatchTag.java

/** {@inheritDoc} */
@Override/*from  w  w  w.  j  a v a2s. c  o  m*/
public void doCatch(Throwable t) {
    if (StringUtils.isNotBlank(throwableVariableName)) {
        pageContext.setAttribute(throwableVariableName, t, PageContext.PAGE_SCOPE);
    }

    logger.error("Exception in JSP", t);
    if (isRender()) {
        PrintWriter out = new PrintWriter(pageContext.getOut());
        out.println("<pre class=\"stacktrace\">");
        t.printStackTrace(out);
        out.println("</pre>");
    }
}

From source file:com.draagon.meta.web.tag.MetaObjectTag.java

public int doStartTag() throws JspException {
    try {//from   w ww.j a v a 2  s.  co  m
        Object o = pageContext.getRequest().getAttribute(getName());
        if (o == null)
            return Tag.SKIP_BODY;

        //log.debug( "(doStartTag) Meta Object found with id [" + mo.getId() + "]" );

        MetaObject mc = MetaDataLoader.findMetaObject(o);

        if (mc == null) {
            log.error("Cannot find MetaClass for object [" + o + "]");
            return Tag.SKIP_BODY;
        }

        MetaField mf = mc.getMetaField(getField());
        if (mf == null) {
            log.error("Cannot find MetaField for MetaClass [" + mc + "] with name [" + getField() + "]");
            return Tag.SKIP_BODY;
        }

        String val = mf.getString(o);

        if (getVar() == null) {
            JspWriter out = pageContext.getOut();
            if (val != null)
                out.print(val);
        } else {
            pageContext.setAttribute(getVar(), val, PageContext.PAGE_SCOPE);
        }
    } catch (Exception e) {
        log.error("Error processing Meta Object Tag [name:" + getName() + ", field:" + getField() + "]", e);
        throw new JspException(
                "Error processing Meta Object Tag [name:" + getName() + ", field:" + getField() + "]: " + e);
    }

    return Tag.SKIP_BODY;
}

From source file:com.gisgraphy.webapp.taglib.ConstantsTag.java

/**
 * Main method that does processing and exposes Constants in specified scope
 * /*from www  . j  a va2 s.  c  o m*/
 * @return int
 * @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:com.steeleforge.aem.ironsites.i18n.taglib.I18nHelperTag.java

public int doEndTag() throws JspException {
    try {//w  ww.  java2s.  c  om
        init();

        ValueMap valueMap = request.getResource().adaptTo(ValueMap.class);
        I18nResourceBundle bundle = new I18nResourceBundle(valueMap, getResourceBundle(getBaseName(), request));

        // make this resource bundle & i18n available as ValueMap for TEI
        pageContext.setAttribute(getMessagesName(), bundle.adaptTo(ValueMap.class), PageContext.PAGE_SCOPE);
        pageContext.setAttribute(getI18nName(), new I18n(bundle), PageContext.PAGE_SCOPE);

        // make this resource bundle available for fmt functions
        Config.set(pageContext, "javax.servlet.jsp.jstl.fmt.localizationContext",
                new LocalizationContext(bundle, getLocale(request)), 1);
    } catch (Exception e) {
        LOG.error(e.getMessage());
        throw new JspException(e);
    }
    return EVAL_PAGE;
}

From source file:alpha.portal.webapp.taglib.ConstantsTag.java

/**
 * Main method that does processing and exposes Constants in specified
 * scope.//from   w w  w.  j  ava 2  s  . co  m
 * 
 * @return int
 * @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 (this.scope != null) {
        toScope = this.getScope(this.scope);
    }

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

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

            AccessibleObject.setAccessible(fields, true);

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

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

From source file:info.magnolia.cms.taglibs.Out.java

/**
 * Setter for <code>scope</code>.
 * @param scope The scope to set.//www.j  a v  a 2s  .  c  o  m
 */
public void setScope(String scope) {
    if ("request".equalsIgnoreCase(scope)) { //$NON-NLS-1$
        this.scope = PageContext.REQUEST_SCOPE;
    } else if ("session".equalsIgnoreCase(scope)) { //$NON-NLS-1$
        this.scope = PageContext.SESSION_SCOPE;
    } else if ("application".equalsIgnoreCase(scope)) { //$NON-NLS-1$
        this.scope = PageContext.APPLICATION_SCOPE;
    } else {
        // default
        this.scope = PageContext.PAGE_SCOPE;
    }
}