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.logic.TestIterateTag.java

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

    String testKey = "testRequestScopeNameIterateMap";

    HashMap map = new HashMap();
    for (int i = 0; i < iterations; i++) {
        map.put("test" + i, "test" + i);
    }/*from  ww  w.  ja  va  2s  .  c  o m*/

    pageContext.setAttribute(testKey, map, 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(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 testRequestScopePropertyIterateMap() throws ServletException, JspException, IOException {

    String testKey = "testRequestScopePropertyIterateMap";

    HashMap map = new HashMap();
    for (int i = 0; i < iterations; i++) {
        map.put("test" + i, "test" + i);
    }//from w  w w  . ja v  a 2  s  .co m

    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    sbft.setMap(map);

    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("map");

    int iteration = 0;
    tag.doStartTag();
    tag.doInitBody();
    do {
        out.print(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 testRequestScopeNameIterateArray() throws ServletException, JspException, IOException {

    String testKey = "testRequestScopeNameIterateArray";

    String[] tst = new String[iterations];
    for (int i = 0; i < tst.length; i++) {
        tst[i] = "test" + i;
    }/*from ww w  .  jav a2  s  .  co m*/

    pageContext.setAttribute(testKey, tst, 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(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 testRequestScopePropertyIterateArray() throws ServletException, JspException, IOException {

    String testKey = "testRequestScopePropertyIterateArray";

    String[] tst = new String[iterations];
    for (int i = 0; i < tst.length; i++) {
        tst[i] = "test" + i;
    }//from  w w  w.  j a v a  2s .co  m

    SimpleBeanForTesting sbft = new SimpleBeanForTesting();
    sbft.setArray(tst);

    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("array");

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

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

From source file:org.apache.struts.taglib.TagUtils.java

/**
 * Returns the appropriate MessageResources object for the current module
 * and the given bundle.//www.j av  a 2 s. com
 *
 * @param pageContext    Search the context's scopes for the resources.
 * @param bundle         The bundle name to look for.  If this is
 *                       <code>null</code>, the default bundle name is
 *                       used.
 * @param checkPageScope Whether to check page scope
 * @return MessageResources The bundle's resources stored in some scope.
 * @throws JspException if the MessageResources object could not be
 *                      found.
 */
public MessageResources retrieveMessageResources(PageContext pageContext, String bundle, boolean checkPageScope)
        throws JspException {
    MessageResources resources = null;

    if (bundle == null) {
        bundle = Globals.MESSAGES_KEY;
    }

    if (checkPageScope) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.PAGE_SCOPE);
    }

    if (resources == null) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.REQUEST_SCOPE);
    }

    if (resources == null) {
        ModuleConfig moduleConfig = getModuleConfig(pageContext);

        resources = (MessageResources) pageContext.getAttribute(bundle + moduleConfig.getPrefix(),
                PageContext.APPLICATION_SCOPE);
    }

    if (resources == null) {
        resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.APPLICATION_SCOPE);
    }

    if (resources == null) {
        JspException e = new JspException(messages.getMessage("message.bundle", bundle));

        saveException(pageContext, e);
        throw e;
    }

    return resources;
}

From source file:org.apache.struts.taglib.TestTagUtils.java

public void testMessageRequestBadKey() {
    putBundleInScope(PageContext.REQUEST_SCOPE, true);

    String val = null;

    try {//  w  w w  .  j  a  va  2s. c  om
        val = tagutils.message(pageContext, null, null, "foo.bar.does.not.exist");
        assertNull(val);
    } catch (JspException e) {
        fail("val should be null, no exception");
    }
}

From source file:org.apache.struts.taglib.TestTagUtils.java

public void testMessageRequestGoodKey() {
    putBundleInScope(PageContext.REQUEST_SCOPE, true);

    String val = null;

    try {//from  w ww  .  j  a  v  a2s .com
        val = tagutils.message(pageContext, null, null, "foo");
        assertTrue("Validate message value", "bar".equals(val));
    } catch (JspException e) {
        fail("val should be \"bar\"");
    }
}

From source file:org.apache.struts.taglib.TestTagUtils.java

/**
 * Tests for://from   w w  w.  jav  a 2s. c  o m
 *
 * public String message( PageContext pageContext, String bundle, String
 * locale, String key, Object args[]) throws JspException
 */
public void testMessageRequestGoodKeyWithNullParams() {
    putBundleInScope(PageContext.REQUEST_SCOPE, true);

    String[] args = null;

    String val = null;

    try {
        val = tagutils.message(pageContext, null, null, "foo", args);
        assertTrue("Validate message value", "bar".equals(val));
    } catch (JspException e) {
        fail("val should be \"bar\"");
    }
}

From source file:org.apache.struts.taglib.TestTagUtils.java

public void testMessageApplicationGoodKeyWithNullParams() {
    putBundleInScope(PageContext.REQUEST_SCOPE, true);

    String[] args = null;/*from w ww. j  a va 2  s.co m*/

    String val = null;

    try {
        val = tagutils.message(pageContext, null, null, "foo", args);
        assertTrue("Validate message value", "bar".equals(val));
    } catch (JspException e) {
        fail("val should be \"bar\"");
    }
}

From source file:org.apache.struts.taglib.TestTagUtils.java

public void testMessageRequestGoodKeyWithParams() {
    putBundleInScope(PageContext.REQUEST_SCOPE, true);

    String[] args = { "I love this" };

    String val = null;

    try {/*from   w w w . java  2 s. c  om*/
        val = tagutils.message(pageContext, null, null, "foo.bar", args);
        assertTrue("Validate message value", "I love this bar".equals(val));
    } catch (JspException e) {
        fail("val should be \"bar\"");
    }
}