@RequestMapping(value = "/persistThisCategory.php", method = RequestMethod.POST)
  public String persistThisCategory(
      @ModelAttribute("productLocationModel") ProductLocationModel productLocationModel,
      BindingResult result) {
    if (result.hasErrors()) {
      return "add";
    }

    try {
      List<Product> products = new ArrayList<Product>();
      List<ProductLocation> productLocations1 = new ArrayList<ProductLocation>();

      productLocations = productLocationServices.addProductLocation(productLocationModel);
      productLocations1.add(productLocations);
      product.setProductLocations(productLocations1);
      products.add(product);
      category.setProducts(products);
      dataCrudService.getCategoryCrudService().persist(category);
      productLocations = productLocationServices.addProductLocation(null);
    } catch (NullPointerException e) {
      return "redirect:category.html";
    }
    return "redirect:category.html";
  }
/** @author Ronalds */
@Controller
@SessionAttributes
public class PersistCategoryController {

  @Autowired private CategoryServices categoryServices;
  @Autowired private ProductServices productServices;
  @Autowired private ProductLocationServices productLocationServices;
  private Category category;
  private Product product;
  private ProductLocation productLocations;
  CategoryFacade dataCrudService = CategoryFacade.getCategoryFacadeInstance();

  @RequestMapping(value = "/persistCategory.php", method = RequestMethod.POST)
  public String persistCategory(
      @ModelAttribute("categoryModel") CategoryModel categoryModel, BindingResult result) {
    if (result.hasErrors()) {
      return "add";
    }
    category = categoryServices.addCategory(categoryModel);
    return "redirect:addProduct.html";
  }

  @RequestMapping(value = "/persistProduct.php", method = RequestMethod.POST)
  public String persistProduct(
      @ModelAttribute("productModel") ProductModel productModel, BindingResult result) {
    if (result.hasErrors()) {
      return "add";
    }
    product = productServices.addProduct(productModel);
    return "redirect:addProductLocations.html";
  }

  @RequestMapping(value = "/persistProductLocation.php", method = RequestMethod.POST)
  public String persistProductLocation(
      @ModelAttribute("productLocationModel") ProductLocationModel productLocationModel,
      BindingResult result) {
    if (result.hasErrors()) {
      return "add";
    }
    productLocations = productLocationServices.addProductLocation(productLocationModel);
    return "redirect:addProductLocations.html";
  }

  @RequestMapping(value = "/persistThisCategory.php", method = RequestMethod.POST)
  public String persistThisCategory(
      @ModelAttribute("productLocationModel") ProductLocationModel productLocationModel,
      BindingResult result) {
    if (result.hasErrors()) {
      return "add";
    }

    try {
      List<Product> products = new ArrayList<Product>();
      List<ProductLocation> productLocations1 = new ArrayList<ProductLocation>();

      productLocations = productLocationServices.addProductLocation(productLocationModel);
      productLocations1.add(productLocations);
      product.setProductLocations(productLocations1);
      products.add(product);
      category.setProducts(products);
      dataCrudService.getCategoryCrudService().persist(category);
      productLocations = productLocationServices.addProductLocation(null);
    } catch (NullPointerException e) {
      return "redirect:category.html";
    }
    return "redirect:category.html";
  }
}