Package org.springframework.web.servlet.support

Examples of org.springframework.web.servlet.support.BindStatus


    assertEquals("Incorrect number of children", 0, children.size());
  }

  public void testWithoutItems() throws Exception {
    getPageContext().setAttribute(
        SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.country", false));

    this.tag.setItemValue("isoCode");
    this.tag.setItemLabel("name");
    int result = this.tag.doStartTag();
    assertEquals(Tag.SKIP_BODY, result);
View Full Code Here


  public void testWithJavaEnum() throws Exception {
    GenericBean testBean = new GenericBean();
    testBean.setCustomEnum(CustomEnum.VALUE_1);
    getPageContext().getRequest().setAttribute("testBean", testBean);
    getPageContext().setAttribute(SelectTag.LIST_VALUE_PAGE_ATTRIBUTE, new BindStatus(getRequestContext(), "testBean.customEnum", false));

    this.tag.setValue("VALUE_1");

    int result = this.tag.doStartTag();
    assertEquals(BodyTag.EVAL_BODY_BUFFERED, result);
View Full Code Here

    @Override
    protected ProcessorResult processAttribute(Arguments arguments, Element element, String attributeName) {
        String attributeValue = element.getAttributeValue(attributeName);
       
        BindStatus bindStatus = FieldUtils.getBindStatus(arguments.getConfiguration(), arguments, attributeValue);
       
        if (bindStatus.isError()) {
            EntityForm form = (EntityForm) ((BindingResult)bindStatus.getErrors()).getTarget();
           
            // Map of tab name -> (Map field Name -> list of error messages)
            Map<String, Map<String, List<String>>> result = new HashMap<String, Map<String, List<String>>>();
            for (FieldError err : bindStatus.getErrors().getFieldErrors()) {
                //attempt to look up which tab the field error is on. If it can't be found, just use
                //the default tab for the group
                String tabName = EntityForm.DEFAULT_TAB_NAME;
                Tab tab = form.findTabForField(err.getField());
                if (tab != null) {
                    tabName = tab.getTitle();
                }
               
                Map<String, List<String>> tabErrors = result.get(tabName);
                if (tabErrors == null) {
                    tabErrors = new HashMap<String, List<String>>();
                    result.put(tabName, tabErrors);
                }
                if (err.getField().contains(DynamicEntityFormInfo.FIELD_SEPARATOR)) {
                    //at this point the field name actually occurs within some array syntax
                    String fieldName = err.getField().substring(err.getField().indexOf('[') + 1, err.getField().lastIndexOf(']'));
                    String[] fieldInfo = fieldName.split("\\" + DynamicEntityFormInfo.FIELD_SEPARATOR);
                    Field formField = form.getDynamicForm(fieldInfo[0]).getFields().get(fieldName);
                   
                    if (formField != null) {
                        addFieldError(formField.getFriendlyName(), err.getCode(), tabErrors);
                    } else {
                        LOG.warn("Could not find field " + fieldName + " within the dynamic form " + fieldInfo[0]);
                        addFieldError(fieldName, err.getCode(), tabErrors);
                    }
                } else {
                    Field formField = form.findField(err.getField());
                    if (formField != null) {
                        addFieldError(formField.getFriendlyName(), err.getCode(), tabErrors);
                    } else {
                        LOG.warn("Could not field field " + err.getField() + " within the main form");
                        addFieldError(err.getField(), err.getCode(), tabErrors);
                    }
                }
            }
           
            for (ObjectError err : bindStatus.getErrors().getGlobalErrors()) {
                Map<String, List<String>> tabErrors = result.get(GENERAL_ERRORS_TAB_KEY);
                if (tabErrors == null) {
                    tabErrors = new HashMap<String, List<String>>();
                    result.put(GENERAL_ERRORS_TAB_KEY, tabErrors);
                }
View Full Code Here

  /**
   * @see org.springframework.web.servlet.support.RequestContext#getBindStatus(String)
   */
  public BindStatus getBindStatus(String path) throws IllegalStateException {
    return new BindStatus(new RequestContext(this.request), path, false);
  }
View Full Code Here

  /**
   * @see org.springframework.web.servlet.support.RequestContext#getBindStatus(String, boolean)
   */
  public BindStatus getBindStatus(String path, boolean htmlEscape) throws IllegalStateException {
    return new BindStatus(new RequestContext(this.request), path, true);
  }
View Full Code Here

  /**
   * Returns '{@code true}' if the bound value requires the
   * resultant '{@code select}' tag to be multi-select.
   */
  private boolean forceMultiple() throws JspException {
    BindStatus bindStatus = getBindStatus();
    Class<?> valueType = bindStatus.getValueType();
    if (valueType != null && typeRequiresMultiple(valueType)) {
      return true;
    }
    else if (bindStatus.getEditor() != null) {
      Object editorValue = bindStatus.getEditor().getValue();
      if (editorValue != null && typeRequiresMultiple(editorValue.getClass())) {
        return true;
      }
    }
    return false;
View Full Code Here

      protected void processTemplate(Template template, SimpleHash fmModel, HttpServletResponse response)
          throws TemplateException {
        Map model = fmModel.toMap();
        assertTrue(model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext);
        RequestContext rc = (RequestContext) model.get(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
        BindStatus status = rc.getBindStatus("tb.name");
        assertEquals("name", status.getExpression());
        assertEquals("juergen", status.getValue());
      }
    };
    fv.setUrl(TEMPLATE_FILE);
    fv.setApplicationContext(wac);
    fv.setExposeSpringMacroHelpers(true);
View Full Code Here

    VelocityView vv = new VelocityView() {
      @Override
      protected void mergeTemplate(Template template, Context context, HttpServletResponse response) {
        assertTrue(context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE) instanceof RequestContext);
        RequestContext rc = (RequestContext) context.get(VelocityView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
        BindStatus status = rc.getBindStatus("tb.name");
        assertEquals("name", status.getExpression());
        assertEquals("juergen", status.getValue());
      }
    };
    vv.setUrl(TEMPLATE_FILE);
    vv.setApplicationContext(wac);
    vv.setExposeSpringMacroHelpers(true);
View Full Code Here

    pc.getRequest().setAttribute(BindingResult.MODEL_KEY_PREFIX + "tb", errors);
    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertTrue("Correct expression", status.getExpression() == null);
    assertTrue("Correct value", status.getValue() == null);
    assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
    assertTrue("Correct isError", !status.isError());
    assertTrue("Correct errorCodes", status.getErrorCodes().length == 0);
    assertTrue("Correct errorMessages", status.getErrorMessages().length == 0);
    assertTrue("Correct errorCode", "".equals(status.getErrorCode()));
    assertTrue("Correct errorMessage", "".equals(status.getErrorMessage()));
    assertTrue("Correct errorMessagesAsString", "".equals(status.getErrorMessagesAsString(",")));
  }
View Full Code Here

    BindTag tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    BindStatus status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertTrue("Correct expression", status.getExpression() == null);
    assertTrue("Correct value", status.getValue() == null);
    assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
    assertTrue("Correct isError", status.isError());
    assertTrue("Correct errorCodes", status.getErrorCodes().length == 1);
    assertTrue("Correct errorMessages", status.getErrorMessages().length == 1);
    assertTrue("Correct errorCode", "code1".equals(status.getErrorCode()));
    assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessage()));
    assertTrue("Correct errorMessagesAsString", "message1".equals(status.getErrorMessagesAsString(",")));

    tag = new BindTag();
    tag.setPageContext(pc);
    tag.setPath("tb.*");
    assertTrue("Correct doStartTag return value", tag.doStartTag() == Tag.EVAL_BODY_INCLUDE);
    status = (BindStatus) pc.getAttribute(BindTag.STATUS_VARIABLE_NAME, PageContext.REQUEST_SCOPE);
    assertTrue("Has status variable", status != null);
    assertTrue("Correct expression", "*".equals(status.getExpression()));
    assertTrue("Correct value", status.getValue() == null);
    assertTrue("Correct displayValue", "".equals(status.getDisplayValue()));
    assertTrue("Correct isError", status.isError());
    assertTrue("Correct errorCodes", status.getErrorCodes().length == 1);
    assertTrue("Correct errorMessages", status.getErrorMessages().length == 1);
    assertTrue("Correct errorCode", "code1".equals(status.getErrorCode()));
    assertTrue("Correct errorMessage", "message1".equals(status.getErrorMessage()));
    assertTrue("Correct errorMessagesAsString", "message1".equals(status.getErrorMessagesAsString(",")));
  }
View Full Code Here

TOP

Related Classes of org.springframework.web.servlet.support.BindStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.