Example usage for org.springframework.validation BindingResult getSuppressedFields

List of usage examples for org.springframework.validation BindingResult getSuppressedFields

Introduction

In this page you can find the example usage for org.springframework.validation BindingResult getSuppressedFields.

Prototype

default String[] getSuppressedFields() 

Source Link

Document

Return the list of fields that were suppressed during the bind process.

Usage

From source file:com.mum.controller.ProductController.java

@RequestMapping(value = "products/add", method = RequestMethod.POST)
public String processAddNewProductForm(@ModelAttribute("newProduct") Product product, BindingResult result,
        HttpServletRequest request, HttpServletResponse response) {
    MultipartFile productImage = product.getProductImage();
    String rootDirectory = request.getSession().getServletContext().getRealPath("/../../../");

    if (productImage != null && !productImage.isEmpty()) {
        try {/*from ww w  .ja  v a 2 s . c o  m*/
            productImage.transferTo(
                    new File(rootDirectory + "\\images\\" + productImage.getOriginalFilename() + ".png"));
        } catch (Exception e) {
            throw new RuntimeException("Product Image saving failed", e);
        }
    }

    String[] suppressedFields = result.getSuppressedFields();
    if (suppressedFields.length > 0) {
        throw new RuntimeException("Attempting to bind disallowed fields:"
                + StringUtils.arrayToCommaDelimitedString(suppressedFields));
    }

    productService.addProduct(product);
    //return "redirect:/products/add";
    //return "redirect:/products";
    return "";
}