Class CartView

java.lang.Object
springboot.bg.harisauto.cart.CartView

public final class CartView extends Object
CartView.java - Immutable snapshot of a ShoppingCart, safe to render.

The cart itself is a session-scoped proxy. Touching it from a template can force the container to create an HTTP session part-way through rendering, which fails once the response has been committed and truncates the page. Reading the cart into this snapshot inside the controller keeps that work before the response is written.

Author:
Kristian Popov
  • Method Details

    • of

      public static CartView of(ShoppingCart cart)
      Takes a snapshot of the given cart.
      Parameters:
      cart - The session-scoped cart.
      Returns:
      A detached view of its contents.
    • getItems

      public List<CarService> getItems()
    • getCount

      public int getCount()
    • getTotal

      public BigDecimal getTotal()