protected void exposeBindingResult(Errors errors) {
    // wrap errors in a Model
    Map model = new HashMap();
    model.put(BindingResult.MODEL_KEY_PREFIX + COMMAND_NAME, errors);

    // replace the request context with one containing the errors
    MockPageContext pageContext = getPageContext();
    RequestContext context =
        new RequestContext((HttpServletRequest) pageContext.getRequest(), model);
    pageContext.setAttribute(RequestContextAwareTag.REQUEST_CONTEXT_PAGE_ATTRIBUTE, context);
  }
Example #2
0
  public void testVarDefaultScope() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");

    tag.doStartTag();
    tag.doEndTag();

    assertEquals("url/path", context.getAttribute("var", PageContext.PAGE_SCOPE));
  }
Example #3
0
  public void testVarExplicitScope() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");
    tag.setScope("request");

    tag.doStartTag();
    tag.doEndTag();

    assertEquals("url/path", context.getAttribute("var", PageContext.REQUEST_SCOPE));
  }
Example #4
0
  public void testCreateUrlLocalContext() throws JspException {
    ((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context");

    tag.setValue("/url/path");

    tag.doStartTag();

    String uri = invokeCreateUrl(tag);

    assertEquals("/app-context/url/path", uri);
  }
  @Test
  public void createUrlRemoteContextSingleSlash() throws JspException {
    ((MockHttpServletRequest) context.getRequest()).setContextPath("/app-context");

    tag.setValue("/url/path");
    tag.setContext("/");

    tag.doStartTag();

    String uri = invokeCreateUrl(tag);

    assertEquals("/url/path", uri);
  }
Example #6
0
  public void testSetHtmlEscapeDefault() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");

    tag.doStartTag();

    Param param = new Param();
    param.setName("n me");
    param.setValue("v&l=e");
    tag.addParam(param);

    param = new Param();
    param.setName("name");
    param.setValue("value2");
    tag.addParam(param);

    tag.doEndTag();

    assertEquals("url/path?n%20me=v%26l%3De&name=value2", context.getAttribute("var"));
  }
  @Test
  public void setJavaScriptEscapeTrue() throws JspException {
    tag.setValue("url/path");
    tag.setVar("var");
    tag.setJavaScriptEscape(true);

    tag.doStartTag();

    Param param = new Param();
    param.setName("n me");
    param.setValue("v&l=e");
    tag.addParam(param);

    param = new Param();
    param.setName("name");
    param.setValue("value2");
    tag.addParam(param);

    tag.doEndTag();

    assertEquals("url\\/path?n%20me=v%26l%3De&name=value2", context.getAttribute("var"));
  }