- replaced "static add-call" to event-based approach. This is much more flexible and easier to expand
- updated jar(s)
// Trace message
//this.getLogger().logTrace(MessageFormat.format("addItem: item {0} - has been added to basket. - EXIT!", item));
+
// Added
return "item_added"; //NOI18N
} catch (final BasketItemAlreadyAddedException ex) {
// Trace message
//this.getLogger().logTrace(MessageFormat.format("calculateItemPrice: totalPrice={0} - EXIT!", totalPrice));
+
// Return it
return totalPrice;
}
@Override
public void clear () {
// Clear bean as well
- this.basketBean.clear();
+ this.getBasketBean().clear();
// Deligate to basket instance
this.basket.clear();
// Trace message
//this.getLogger().logTrace(MessageFormat.format("doChangeItem: targetPage={0} - EXIT!", targetPage));
+
// Return page
return targetPage;
}
// Trace message
//this.getLogger().logTrace(MessageFormat.format("getItemAmount: itemAmount={0} - EXIT!", itemAmount));
+
// Return it
return itemAmount;
}
// Debug message
//this.getLogger().logDebug(MessageFormat.format("isProductAdded: fake={0}", fake));
+
// Ask bean about it
boolean isAdded = this.basket.isAdded(fake);
// Debug message
//this.getLogger().logDebug(MessageFormat.format("isProductAdded: isAdded={0}", isAdded));
+
// Is it added?
if (isAdded) {
// Get item
// Trace message
//this.getLogger().logTrace(MessageFormat.format("isProductAdded: isAdded={0} - EXIT!", isAdded));
+
// Return status
return isAdded;
}
// Trace message
//this.getLogger().logTrace(MessageFormat.format("outputLastAddedItem: lastItem={0} - EXIT!", lastItem));
+
// Return it
return lastItem;
}
// Debug message
//this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: fake={0}", fake));
+
// Get all items
List<AddableBasketItem> list = this.basket.getAll();
// Debug message
//this.getLogger().logDebug(MessageFormat.format("getItemFromProduct: list={0}", list));
+
// Check all entries
for (final AddableBasketItem item : list) {
// Debug message
// Trace message
//this.getLogger().logTrace(MessageFormat.format("getItemFromProduct: foundItem={0} - EXIT!", foundItem));
+
// Return it
return foundItem;
}
package org.mxchange.pizzaapplication.beans.category;
import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Inject;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.mxchange.jshopcore.events.category.AddedCategoryEvent;
+import org.mxchange.jshopcore.events.category.ShopCategoryAddedEvent;
import org.mxchange.jshopcore.exceptions.CannotAddCategoryException;
import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException;
import org.mxchange.jshopcore.model.category.AdminCategorySessionBeanRemote;
import org.mxchange.jshopcore.model.category.Category;
import org.mxchange.jshopcore.model.category.ProductCategory;
-import org.mxchange.pizzaapplication.beans.shop.PizzaShopWebApplicationController;
/**
* Main application class
*/
private static final long serialVersionUID = 5_819_375_183_472_871L;
+ /**
+ * Event for added shop categories
+ */
+ @Inject
+ @Any
+ private Event<AddedCategoryEvent> categoryAddedEvent;
+
/**
* Remote bean for categories
*/
*/
private Category parentCategory;
- ////////////////////// Bean injections ///////////////////////
-
- /**
- * Shop bean
- */
- @Inject
- private PizzaShopWebApplicationController shopController;
-
/**
* Default constructor
*/
// Deligate to remote bean
Category updatedCategory = this.categoryBean.doAdminAddCategory(category);
- // Also send it to the controller bean
- this.shopController.addCategory(updatedCategory);
+ // Fire event
+ this.categoryAddedEvent.fire(new ShopCategoryAddedEvent(updatedCategory));
// Unset all older values
this.setCategoryTitle(""); //NOI18N
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.event.Observes;
import javax.faces.FacesException;
import javax.faces.view.facelets.FaceletException;
import javax.inject.Named;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.mxchange.jshopcore.events.category.AddedCategoryEvent;
import org.mxchange.jshopcore.model.category.Category;
import org.mxchange.jshopcore.model.category.CategorySessionBeanRemote;
import org.mxchange.jshopcore.model.product.Product;
}
}
+ @Override
+ public void afterShopCategoryAdded (@Observes final AddedCategoryEvent event) {
+ // Add it here, too.
+ this.addCategory(event.getAddedCategory());
+ }
+
@Override
public List<Category> getAllCategories () throws FacesException {
// Return it
@Override
public List<Product> getAvailableProducts () throws FacesException {
// Return it
- // TODO Find something better here to prevent warning
return Collections.unmodifiableList(this.availableProducts);
}
import java.io.Serializable;
import java.util.List;
import javax.faces.view.facelets.FaceletException;
+import org.mxchange.jshopcore.events.category.AddedCategoryEvent;
import org.mxchange.jshopcore.model.category.Category;
import org.mxchange.jshopcore.model.product.Product;
* Adds given category to the "cached" instance
* <p>
* @param category Category instance
+ * @todo Move this to own controller
*/
void addCategory (final Category category);
* @return All categories
* <p>
* @throws javax.faces.view.facelets.FaceletException If anything went wrong
+ * @todo Move this to own controller
*/
List<Category> getAllCategories () throws FaceletException;
* @return All categories
* <p>
* @throws javax.faces.view.facelets.FaceletException If anything went wrong
+ * @todo Move this to own controller
*/
List<Category> getAllCategoriesParent () throws FaceletException;
*/
List<Product> getAvailableProducts () throws FaceletException;
+ /**
+ * Observes events fired after a new product category has been added
+ * <p>
+ * @param event Event to be observed
+ * @todo Move this to own controller
+ */
+ void afterShopCategoryAdded (final AddedCategoryEvent event);
}