Example usage for javax.servlet.jsp PageContext REQUEST_SCOPE

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

Introduction

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

Prototype

int REQUEST_SCOPE

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

Click Source Link

Document

Request scope: the named reference remains available from the ServletRequest associated with the Servlet until the current request is completed.

Usage

From source file:org.apache.struts.taglib.bean.TestWriteTag.java

public void testWriteTagNameFormatKeyAlternateBundle_fr() {
    pageContext.setAttribute(REQUEST_KEY, TEST_DOUBLE_VAL, PageContext.REQUEST_SCOPE);
    runMyTest("testWriteTagNameFormatKeyAlternateBundle", "fr");
}

From source file:org.apache.struts.taglib.bean.TestWriteTag.java

public void testWriteTagNamePropertyFormat() {
    SimpleBeanForTesting sbft = new SimpleBeanForTesting(TEST_INTEGER_VAL);
    pageContext.setAttribute(REQUEST_KEY, sbft, PageContext.REQUEST_SCOPE);
    runMyTest("testWriteTagNamePropertyFormat", "");
}

From source file:org.apache.struts.taglib.bean.TestWriteTag.java

public void testWriteTagNameFilter() {
    pageContext.setAttribute(REQUEST_KEY, "<testing&'\">", PageContext.REQUEST_SCOPE);
    runMyTest("testWriteTagNameFilter", "");
}

From source file:org.apache.struts.taglib.html.BaseHandlerTag.java

/**
 * Prepares the focus event handlers, appending them to the the given
 * StringBuffer.//from   www .  j a va2  s. c  om
 *
 * @param handlers The StringBuffer that output will be appended to.
 */
protected void prepareFocusEvents(StringBuffer handlers) {
    prepareAttribute(handlers, "onblur", getOnblur());
    prepareAttribute(handlers, "onfocus", getOnfocus());

    // Get the parent FormTag (if necessary)
    FormTag formTag = null;

    if ((doDisabled && !getDisabled()) || (doReadonly && !getReadonly())) {
        formTag = (FormTag) pageContext.getAttribute(Constants.FORM_KEY, PageContext.REQUEST_SCOPE);
    }

    // Format Disabled
    if (doDisabled) {
        boolean formDisabled = (formTag == null) ? false : formTag.isDisabled();

        if (formDisabled || getDisabled()) {
            handlers.append(" disabled=\"disabled\"");
        }
    }

    // Format Read Only
    if (doReadonly) {
        boolean formReadOnly = (formTag == null) ? false : formTag.isReadonly();

        if (formReadOnly || getReadonly()) {
            handlers.append(" readonly=\"readonly\"");
        }
    }
}

From source file:org.apache.struts.taglib.html.JavascriptValidatorTag.java

/**
 * Generates the dynamic JavaScript for the form.
 *
 * @param config//from  w  w  w  .j  ava  2  s  .  co  m
 * @param resources
 * @param locale
 * @param form
 */
private String createDynamicJavascript(ModuleConfig config, ValidatorResources resources, Locale locale,
        Form form) throws JspException {
    StringBuffer results = new StringBuffer();

    MessageResources messages = TagUtils.getInstance().retrieveMessageResources(pageContext, bundle, true);

    HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
    ServletContext application = pageContext.getServletContext();

    List actions = this.createActionList(resources, form);

    final String methods = this.createMethods(actions, this.stopOnError(config));

    String formName = form.getName();

    jsFormName = formName;

    if (jsFormName.charAt(0) == '/') {
        String mappingName = TagUtils.getInstance().getActionMappingName(jsFormName);
        ActionMapping mapping = (ActionMapping) config.findActionConfig(mappingName);

        if (mapping == null) {
            JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName));

            pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
            throw e;
        }

        jsFormName = mapping.getAttribute();
    }

    results.append(this.getJavascriptBegin(methods));

    for (Iterator i = actions.iterator(); i.hasNext();) {
        ValidatorAction va = (ValidatorAction) i.next();
        int jscriptVar = 0;
        String functionName = null;

        if ((va.getJsFunctionName() != null) && (va.getJsFunctionName().length() > 0)) {
            functionName = va.getJsFunctionName();
        } else {
            functionName = va.getName();
        }

        results.append("    function " + jsFormName + "_" + functionName + " () { \n");

        for (Iterator x = form.getFields().iterator(); x.hasNext();) {
            Field field = (Field) x.next();

            // Skip indexed fields for now until there is a good way to
            // handle error messages (and the length of the list (could
            // retrieve from scope?))
            if (field.isIndexed() || (field.getPage() != page) || !field.isDependency(va.getName())) {
                continue;
            }

            String message = Resources.getMessage(application, request, messages, locale, va, field);

            message = (message != null) ? message : "";

            // prefix variable with 'a' to make it a legal identifier
            results.append("     this.a" + jscriptVar++ + " = new Array(\"" + field.getKey() + "\", \""
                    + escapeQuotes(message) + "\", ");

            results.append("new Function (\"varName\", \"");

            Map vars = field.getVars();

            // Loop through the field's variables.
            Iterator varsIterator = vars.keySet().iterator();

            while (varsIterator.hasNext()) {
                String varName = (String) varsIterator.next();
                Var var = (Var) vars.get(varName);
                String varValue = Resources.getVarValue(var, application, request, false);
                String jsType = var.getJsType();

                // skip requiredif variables field, fieldIndexed, fieldTest,
                // fieldValue
                if (varName.startsWith("field")) {
                    continue;
                }

                String varValueEscaped = escapeJavascript(varValue);

                if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) {
                    results.append("this." + varName + "=" + varValueEscaped + "; ");
                } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) {
                    results.append("this." + varName + "=/" + varValueEscaped + "/; ");
                } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) {
                    results.append("this." + varName + "='" + varValueEscaped + "'; ");

                    // So everyone using the latest format doesn't need to
                    // change their xml files immediately.
                } else if ("mask".equalsIgnoreCase(varName)) {
                    results.append("this." + varName + "=/" + varValueEscaped + "/; ");
                } else {
                    results.append("this." + varName + "='" + varValueEscaped + "'; ");
                }
            }

            results.append(" return this[varName];\"));\n");
        }

        results.append("    } \n\n");
    }

    return results.toString();
}

From source file:org.apache.struts.taglib.html.MultiboxTag.java

/**
 * Render the value element//from   ww w.  jav  a  2 s.  co  m
 *
 * @param results The StringBuffer that output will be appended to.
 */
protected String prepareValue(StringBuffer results) throws JspException {
    String value = (this.value == null) ? this.constant : this.value;

    if (value == null) {
        JspException e = new JspException(messages.getMessage("multiboxTag.value"));

        pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
        throw e;
    }

    prepareAttribute(results, "value", TagUtils.getInstance().filter(value));

    return value;
}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testRequestScopeNameIterateList() throws ServletException, JspException, IOException {

    String testKey = "testRequestScopeNameIterateList";

    ArrayList lst = new ArrayList();
    for (int i = 0; i < iterations; i++) {
        lst.add("test" + i);
    }/*from w w  w . j  a v a 2 s.  c om*/

    pageContext.setAttribute(testKey, lst, PageContext.REQUEST_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("request");

    int iteration = 0;
    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print((String) pageContext.getAttribute("theId"));
        iteration++;

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();
    assertEquals(iterations, iteration);
}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testRequestScopePropertyIteratesList() throws ServletException, JspException, IOException {

    String testKey = "testRequestScopePropertyIterate";

    ArrayList lst = new ArrayList();
    for (int i = 0; i < iterations; i++) {
        lst.add("test" + i);
    }/*  w  w w  .j a  v a2s .  co  m*/

    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    sbft.setList(lst);

    pageContext.setAttribute(testKey, sbft, PageContext.REQUEST_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    /*
     * Tests the equivalent of this tag in a jsp:
     *   <logic:iterate id="theId" name="testRequestScopePropertyIterate"
     *       scope="request">
     */
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("request");
    tag.setProperty("list");

    int iteration = 0;
    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print((String) pageContext.getAttribute("theId"));
        iteration++;

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();
    assertEquals(iterations, iteration);
}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testRequestScopeNameIterateEnumeration() throws ServletException, JspException, IOException {

    String testKey = "testRequestScopeNameIterateEnumeration";

    StringTokenizer st = new StringTokenizer("Request Scope Name Iterate Enumeration");

    pageContext.setAttribute(testKey, st, PageContext.REQUEST_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);/*from www  .  j a v a2 s. c om*/
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("request");

    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print((String) pageContext.getAttribute("theId"));

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();

}

From source file:org.apache.struts.taglib.logic.TestIterateTag.java

public void testRequestScopePropertyIterateEnumeration() throws ServletException, JspException, IOException {

    String testKey = "testRequestScopePropertyIterateEnumeration";

    StringTokenizer st = new StringTokenizer("Request Scope Property Iterate Enumeration");

    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    sbft.setEnumeration(st);//from   www . ja v a  2s . c o  m

    pageContext.setAttribute(testKey, sbft, PageContext.REQUEST_SCOPE);

    IterateTag tag = new IterateTag();
    tag.setPageContext(pageContext);
    tag.setId("theId");
    tag.setName(testKey);
    tag.setScope("request");
    tag.setProperty("enumeration");

    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print((String) pageContext.getAttribute("theId"));

    } while (tag.doAfterBody() == tag.EVAL_BODY_TAG);
    tag.doEndTag();

}