title: Spring MVC + Session attributes and multiple tabs
body: <p>I have some UI where an admin can update products. During my dev/testing, I only ever opened one window, and everything worked as it should.</p>
  
  <p>Then the client was editing, and they opened multiple tabs for different products, and upon saving, this caused a duplicate field issue.</p>
  
  <p>I am assuming this is a combination of <code>@SessionAttributes</code> and <code>@ModelAttribute</code>. The last product opened, is the one put in the session, so if you try edit the first tab, you will actually have the incorrect product.</p>
  
  <p>Is my approach below, using <code>SessionAttribute</code>, and <code>ModelAttribute</code> incorrect?</p>
  
  <p>My Controller:</p>
  
  <pre><code>@Controller
  @SessionAttributes({ "product" })
  public class ProductController {
  
  @RequestMapping(value = "/product/update/{productId}", method = RequestMethod.GET)
  public String update(@PathVariable Long productId, Model model) {
      Product product;
      if (productId == null) {
          product = new Product();
      } else {
          product = Product.find(productId);
      }
      model.addAttribute("product", product);
      return "product/update";
  }
  
  @RequestMapping(value = "/product/update", method = RequestMethod.POST)
  public String update(@ModelAttribute Product product, BindingResult result,
          Model model) {
      if (result.hasErrors()) {
          return "product/update";
      }
      product = product.merge();
      return "redirect:/product/update/" + product.getId();
  }
  </code></pre>
  
  <p>}</p>