Ejemplo n.º 1
0
 private Errors getErrors(String command, RequestContext requestContext) {
   BindStatus status = getStatus(command, requestContext);
   if (status != null) {
     return status.getErrors();
   }
   return null;
 }
Ejemplo n.º 2
0
 public Object getValue(String field) {
   BindStatus status = getFieldStatus(field);
   if (status != null) {
     return status.getValue();
   }
   return null;
 }
Ejemplo n.º 3
0
  public void testSimpleBindTagWithinForm() throws Exception {
    BindTag bindTag = new BindTag();
    bindTag.setPath("name");
    bindTag.setPageContext(getPageContext());
    bindTag.doStartTag();

    BindStatus bindStatus =
        (BindStatus) getPageContext().findAttribute(BindTag.STATUS_VARIABLE_NAME);
    assertEquals("Rob", bindStatus.getValue());
  }
Ejemplo n.º 4
0
 public String getDisplayValue(String field) {
   try {
     BindStatus status = getFieldStatus(field);
     if (status != null) {
       return status.getDisplayValue();
     }
   } catch (Exception e) {
     log.error("Error determing form field display value " + command + "." + field, e);
   }
   return "";
 }
Ejemplo n.º 5
0
  public void testWithNestedBindTagWithinForm() throws Exception {
    NestedPathTag nestedPathTag = new NestedPathTag();
    nestedPathTag.setPath("spouse.");
    nestedPathTag.setPageContext(getPageContext());
    nestedPathTag.doStartTag();

    BindTag bindTag = new BindTag();
    bindTag.setPath("name");
    bindTag.setPageContext(getPageContext());
    bindTag.doStartTag();

    BindStatus bindStatus =
        (BindStatus) getPageContext().findAttribute(BindTag.STATUS_VARIABLE_NAME);
    assertEquals("Sally", bindStatus.getValue());
  }
Ejemplo n.º 6
0
  public void testWithNestedOptions() throws Exception {
    this.tag.setPath("country");
    int result = this.tag.doStartTag();
    assertEquals(Tag.EVAL_BODY_INCLUDE, result);

    BindStatus value =
        (BindStatus) getPageContext().getAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE);
    assertEquals("Selected country not exposed in page context", "UK", value.getValue());

    result = this.tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, result);
    this.tag.doFinally();

    String output = getWriter().toString();

    assertTrue(output.startsWith("<select "));
    assertTrue(output.endsWith("</select>"));
    assertContainsAttribute(output, "name", "country");
  }
  public void testNew() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request = new MockHttpServletRequest("GET", "/workCodeForm.html");
    MockHttpServletResponse response = new MockHttpServletResponse();
    simpleDispatcherServlet.service(request, response);
    ModelAndView mv = child.handleRequest(request, response);

    Map m = mv.getModel();
    log.debug("m = " + m);
    WorkCodeFormBacking backing = (WorkCodeFormBacking) m.get("workCodeFormBacking");
    log.debug(Constants.toReflexString(backing));

    MockPageContext ctx = new MockPageContext();
    Iterator i = m.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      ctx.setAttribute(key, m.get(key));
    }

    RequestContext r = new RequestContext(request, m);

    BindStatus b = r.getBindStatus("workCodeFormBacking.workCode.description");
    log.debug("expression = " + b.getExpression());
    log.debug("value = " + b.getValue());

    String description =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.workCode.description}", String.class, ctx);

    // request.addParameter(name, description);
    String parttime =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.workCode.parttime}", String.class, ctx);
    String code =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.workCode.code}", String.class, ctx);
    String id =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.workCode.id}", String.class, ctx);
    String save =
        (String)
            ExpressionEvaluationUtils.evaluate(
                "test", "${workCodeFormBacking.save}", String.class, ctx);

    log.debug("description = " + description);
    log.debug("parttime = " + parttime);
    log.debug("code = " + code);
    log.debug("id = " + id);
    log.debug("save = " + save);

    HashMap newMap = new HashMap();
    newMap.put(
        r.getBindStatus("workCodeFormBacking.workCode.description").getExpression(), description);
    newMap.put(r.getBindStatus("workCodeFormBacking.workCode.parttime").getExpression(), parttime);
    newMap.put(r.getBindStatus("workCodeFormBacking.workCode.code").getExpression(), code);
    newMap.put(r.getBindStatus("workCodeFormBacking.workCode.id").getExpression(), id);
    newMap.put(r.getBindStatus("workCodeFormBacking.save").getExpression(), "save");

    request = new MockHttpServletRequest("POST", "/workCodeForm.html");
    i = newMap.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      log.debug("add parameter " + key + "  " + newMap.get(key));
      request.addParameter(key, (String) newMap.get(key));
    }
    mv = child.handleRequest(request, response);
    m = mv.getModel();
    log.debug("m = " + m);
    BeanPropertyBindingResult br =
        (BeanPropertyBindingResult)
            m.get("org.springframework.validation.BindingResult.workCodeFormBacking");
    log.debug("field errors " + br.getFieldErrorCount());
    log.debug("errors " + br.getErrorCount());
    assertTrue(br.getFieldError("workCode.code") != null);
    assertTrue(br.getFieldError("workCode.description") != null);
    backing = (WorkCodeFormBacking) m.get("workCodeFormBacking");
    log.debug(response.getErrorMessage());
    log.debug(Constants.toReflexString(backing));
    log.debug("view = " + mv.getViewName());
    assertTrue("workCodeForm".equals(mv.getViewName()));
  }