Reputation: 2209
I have JSF 2.0 e-commerce application. I'm using 2 session scoped beans: ProductBean and CartBean. ProductBean holds Product entity representing current product user is viewing. CartBean holds list of Products. CartBean has method addProduct(Product p). I have problem with adding to cart when using multiple tabs. Here's scenario:
- User visits product page: /product?id=111
- User opens new browser tab for another product: /product?id=222
- User goes back to first tab and clicks 'add to cart' - Second product (id=222) is added to cart.
Here's the code of add to cart commandButton action:
#{cartBean.addProduct(productBean.product)}
It's clear to me what's going on. How can I make this work on multiple tabs?
Upvotes: 0
Views: 1740
Reputation: 3190
Make the ProductBean
request-scoped. If your beans are session-scoped they're global to all requests. Similarly, if they're application-scoped, they're global to all sessions.
Upvotes: 1