From the course: Spring Web MVC 6

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Display the number of items in the cart

Display the number of items in the cart - Spring Tutorial

From the course: Spring Web MVC 6

Display the number of items in the cart

- [Instructor] So now that we have the product details page displayed and the add to cart functionality working, we just need to ensure that this shopping cart at the top horizontal bar is updated with the total number of items in the cart. So let's fix that. Let's go to fragments.html. And if you see on line number 34, this is that section which displays the number of items in the cart. So right now, it is hardcoded to a value of six and that is what you keep seeing here in the page. So let's fix that and ensure that it is dynamically generated according to the number of items in the cart that we kept adding. To do that, let's go ahead and explore this tag on line number 36. So we don't want the six, I will get rid of this hardcoded value. And inside the span tag, I'm going to make a check using th:if. And that check will be to basically check if there is a cart attribute in the session object. So this is an…

Contents