Example usage for org.springframework.validation FieldError getField

List of usage examples for org.springframework.validation FieldError getField

Introduction

In this page you can find the example usage for org.springframework.validation FieldError getField.

Prototype

public String getField() 

Source Link

Document

Return the affected field of the object.

Usage

From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractTenantController.java

protected void parseResult(BindingResult result, ModelMap map) {
    if (result.getFieldErrors().size() > 0) {
        List<String> errorMsgList = new ArrayList<String>();
        for (FieldError fieldError : result.getFieldErrors()) {
            String fieldName = fieldError.getField();
            if (fieldName.contains(".")) {
                fieldName = fieldName.substring(fieldName.lastIndexOf(".") + 1);
            }/*from  www . j  a v a  2  s  .  c  o  m*/
            errorMsgList.add(fieldName + " field value '" + fieldError.getRejectedValue() + "' is not valid.");
        }

        map.addAttribute("errorMsgList", errorMsgList);
        map.addAttribute("errormsg", true);
    }
}

From source file:com.att.pirates.controller.ProjectController.java

@RequestMapping(value = "/updateProjectInfo/{prismId}", method = RequestMethod.POST)
public String updateProjectInfo(@PathVariable("prismId") String prismId,
        @Valid @ModelAttribute("projectInfo") InsightProject projectInfo, BindingResult result) {
    if (result.hasErrors()) {
        logger.error("There are " + result.getErrorCount() + " errors..");
        FieldError er = result.getFieldError();
        logger.error("Field: " + er.getField() + " ErrorMsg: " + er.getDefaultMessage());
    } else {/*from  ww w.j  a  va2 s . c om*/
        String es = HtmlUtils.htmlEscape(projectInfo.getProjectDescription());

        String status = projectInfo.getProjectStatus();
        String release = projectInfo.getReleaseName();
        String startdate = projectInfo.getProjectStartDate();
        String dueDate = projectInfo.getProjectDueDate();
        // lookup statusid and releaseid
        int statusId = DataService.getStatusIdByname(status);
        int releaseId = DataService.getReleaseIdByName(release);

        InsightProject prj = new InsightProject();
        prj.setPrismId(prismId);
        prj.setLeadPM(projectInfo.getLeadPM());
        prj.setProjectDescription(es);
        prj.setProjectDueDate(dueDate);
        prj.setProjectName(HtmlUtils.htmlEscape(projectInfo.getProjectName()));
        prj.setProjectStartDate(startdate);
        prj.setStatudId(statusId);
        prj.setProjectStatus(status);
        prj.setReleaseName(release);
        prj.setReleaseId(releaseId);

        boolean rc = DataService.updateProjectInfo(prj);
        if (!rc) {
            logger.error("DataService.updateProjectInfo(prj); failed");
        }
    }
    // prismId will be considered while expanding the placeholders
    // return "redirect:/impact_pirates/projects/index/{prismId}";
    return "redirect:/projects/index/{prismId}";
}

From source file:com.jaspersoft.jasperserver.war.action.DataSourceAction.java

public Event validateDataSource(RequestContext context) throws Exception {
    Errors errors = getFormErrors(context);

    ReportDataSourceWrapper wrapper = (ReportDataSourceWrapper) getFormObject(context);

    getValidator().validate(wrapper, errors);

    List fieldErrors = errors.getFieldErrors();
    if (fieldErrors != null && !fieldErrors.isEmpty()) {
        FieldError error = (FieldError) fieldErrors.get(0);
        String field = error.getField();

        if ("source".equals(field) || "selectedUri".equals(field)) {
            return result("chooseSource");
        } else if ("type".equals(field)) {
            return result("chooseType");
        } else if (JasperServerConstImpl.getJDBCDatasourceType().equals(wrapper.getType())) {
            return result("jdbcPropsForm");
        } else if (JasperServerConstImpl.getJNDIDatasourceType().equals(wrapper.getType())) {
            return result("jndiPropsForm");
        } else if (JasperServerConstImpl.getBeanDatasourceType().equals(wrapper.getType())) {
            return result("beanPropsForm");
        } else if (JasperServerConstImpl.getVirtualDatasourceType().equals(wrapper.getType())) {
            return result("virtualPropsForm");
        } else {//from  w ww  . ja va2 s. com
            return result("customPropsForm");
        }
    }

    return success();
}

From source file:com.jaspersoft.jasperserver.war.action.ReportDataSourceAction.java

public Event validateDataSource(RequestContext context) throws Exception {
    Errors errors = getFormErrors(context);

    ReportDataSourceWrapper wrapper = (ReportDataSourceWrapper) getFormObject(context);

    getValidator().validate(wrapper, errors);

    List fieldErrors = errors.getFieldErrors();
    if (fieldErrors != null && !fieldErrors.isEmpty()) {
        FieldError error = (FieldError) fieldErrors.get(0);
        String field = error.getField();

        if ("source".equals(field) || "selectedUri".equals(field)) {
            return result("chooseSource");
        } else if ("type".equals(field)) {
            return result("chooseType");
        } else if (JasperServerConstImpl.getJDBCDatasourceType().equals(wrapper.getType())) {
            return result("jdbcPropsForm");
        } else if (JasperServerConstImpl.getJNDIDatasourceType().equals(wrapper.getType())) {
            return result("jndiPropsForm");
        } else if (JasperServerConstImpl.getVirtualDatasourceType().equals(wrapper.getType())) {
            return result("virtualPropsForm");
        } else if (JasperServerConstImpl.getBeanDatasourceType().equals(wrapper.getType())) {
            return result("beanPropsForm");
        } else {/*from w w  w.  ja  v  a 2 s . co m*/
            return result("customPropsForm");
        }
    }

    return success();
}

From source file:com.jaspersoft.jasperserver.war.action.ReportUnitAction.java

public Event validateReport(RequestContext context) throws Exception {

    Errors errors = getFormErrors(context);

    getValidator().validate(getFormObject(context), errors);

    List fieldErrors = errors.getFieldErrors();
    if (fieldErrors != null && !fieldErrors.isEmpty()) {
        FieldError error = (FieldError) fieldErrors.get(0);
        String field = error.getField();

        if ("reportUnit.name".equals(field) || "reportUnit.label".equals(field)
                || "reportUnit.description".equals(field)) {
            return result("displayNameLabelDescForm");
        } else if ("source".equals(field) || "jrxmlData".equals(field)) {
            return result("displayJrxmlUploadForm");
        } else if ("validationMessage".equals(field) || "reportUnit.inputControlRenderingView".equals(field))

        {/*from w w  w.  j  av  a  2 s  .  c  om*/
            return result("listResources");
        }
    }

    log("In Validate Report");
    ReportUnitWrapper ruWrapper = (ReportUnitWrapper) getFormObject(context);
    ReportUnit ru = ruWrapper.getReportUnit();
    ValidationResult result = engine.validate(null, ru);
    ruWrapper.setResult(result.getValidationState().equals(ValidationResult.STATE_VALID));
    return success();
}

From source file:com.octanner.controllers.AbstractProductConfigController.java

protected Map<String, FieldError> handleValidationErrorsBeforeUpdate(final ConfigurationData configData,
        final BindingResult bindingResult) {
    Map<String, FieldError> userInputToRestore;
    final int capacity = (int) (bindingResult.getErrorCount() / 0.75) + 1;
    userInputToRestore = new HashMap(capacity);
    for (final FieldError error : bindingResult.getFieldErrors()) {
        final String fieldPath = error.getField();
        final PathExtractor extractor = new PathExtractor(fieldPath);
        final int groupIndex = extractor.getGroupIndex();
        final int csticIndex = extractor.getCsticsIndex();
        UiGroupData group = configData.getGroups().get(groupIndex);
        for (int i = 0; i < extractor.getSubGroupCount(); i++) {
            group = group.getSubGroups().get(extractor.getSubGroupIndex(i));
        }//from   w w w  .ja v  a2 s. c o  m
        final CsticData cstic = group.getCstics().get(csticIndex);
        userInputToRestore.put(cstic.getKey(), error);
        cstic.setValue(cstic.getLastValidValue());
        cstic.setAdditionalValue("");
    }
    return userInputToRestore;
}

From source file:com.vmware.bdd.rest.advice.RestValidationErrorHandler.java

private ValidationErrors processFieldErrors(List<FieldError> fieldErrors) {
    ValidationErrors dto = new ValidationErrors();

    for (FieldError fieldError : fieldErrors) {
        dto.addError(fieldError.getField(), getError(fieldError));
    }//from w  ww.  j ava2 s.co  m

    return dto;
}