- created product helper bean and moved all product-related methods from generic
to this bean
- added view stubs for edit, delete and show of a generic product
- fixed imports as "add events" now have own package
Signed-off-by: Roland Häder <roland@mxchange.org>
import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
import org.mxchange.jfinancials.beans.BaseFinancialsBean;
import org.mxchange.jfinancials.beans.generic_product.list.FinancialsProductListWebViewController;
-import org.mxchange.jproduct.events.product.AddedProductEvent;
-import org.mxchange.jproduct.events.product.ProductAddedEvent;
+import org.mxchange.jproduct.events.product.added.AddedProductEvent;
+import org.mxchange.jproduct.events.product.added.ProductAddedEvent;
import org.mxchange.jproduct.exceptions.product.ProductAlreadyAddedException;
import org.mxchange.jproduct.model.category.Category;
import org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.jfinancials.beans.BaseFinancialsBean;
-import org.mxchange.jproduct.events.product.AddedProductEvent;
+import org.mxchange.jproduct.events.product.added.AddedProductEvent;
import org.mxchange.jproduct.exceptions.product.ProductNotFoundException;
import org.mxchange.jproduct.model.product.Product;
import org.mxchange.jproduct.model.product.ProductSessionBeanRemote;
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.helper.product;
+
+import java.text.MessageFormat;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.faces.view.ViewScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jfinancials.beans.BaseFinancialsBean;
+import org.mxchange.jfinancials.beans.localization.FinancialsLocalizationSessionController;
+import org.mxchange.jproduct.events.product.created.CreatedProductEvent;
+import org.mxchange.jproduct.events.product.created.ObservableCreatedProductEvent;
+import org.mxchange.jproduct.model.category.Category;
+import org.mxchange.jproduct.model.product.Product;
+
+/**
+ * A helper for product beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("productBeanHelper")
+@ViewScoped
+public class FinancialsProductWebViewHelperBean extends BaseFinancialsBean implements FinancialsProductWebViewHelperController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 17_258_793_567_145_701L;
+
+ /**
+ * Localization controller
+ */
+ @Inject
+ private FinancialsLocalizationSessionController localizationController;
+
+ /**
+ * Product instance
+ */
+ private Product product;
+
+ /**
+ * An event fired when a product id has been converted to a product
+ * instance.
+ */
+ @Inject
+ @Any
+ private Event<ObservableCreatedProductEvent> productCreatedEvent;
+
+ /**
+ * Default constructor
+ */
+ public FinancialsProductWebViewHelperBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Getter for product instance
+ * <p>
+ * @return Product instance
+ */
+ public Product getProduct () {
+ return this.product;
+ }
+
+ /**
+ * Setter for product instance
+ * <p>
+ * @param product Product instance
+ */
+ public void setProduct (final Product product) {
+ this.product = product;
+ }
+
+ /**
+ * Notifies other controllers (backing beans) if a product id has been
+ * successfully converted to a Product instance.
+ */
+ public void notifyControllerProductConverted () {
+ // Validate product instance
+ if (this.getProduct() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.product is null"); //NOI18N
+ } else if (this.getProduct().getProductId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.product.productId is null"); //NOI18N
+ } else if (this.getProduct().getProductId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.product.productId={0} is not valid.", this.getProduct().getProductId())); //NOI18N
+ }
+
+ // Set all fields: user
+ this.productCreatedEvent.fire(new CreatedProductEvent(this.getProduct()));
+ }
+
+ /**
+ * Returns the product name and price. If null is provided, an empty string
+ * is returned.
+ * <p>
+ * @param product Product instance
+ * <p>
+ * @return Product name
+ */
+ public String renderGenericProduct (final Product product) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(10);
+
+ // Is a product set?
+ if (product instanceof Product) {
+ // Is product number given?
+ if (product.getProductNumber() != null) {
+ // Prepend it
+ sb.append(this.getMessageFromBundle("NUMBER")).append(" "); //NOI18N
+ sb.append(product.getProductNumber());
+ sb.append(", "); //NOI18N
+ }
+
+ // Add name and price
+ sb.append(this.getMessageFromBundle(product.getProductI18nKey()));
+
+ // Is there any age group?
+ if (product.getProductAgeGroup() != null) {
+ // Show it
+ sb.append(", ").append(this.getMessageFromBundle(product.getProductAgeGroup().getI18nKey())); //NOI18N
+ }
+
+ // Is there any size?
+ if ((product.getProductSize() != null) && (!product.getProductSize().isEmpty())) {
+ // Show size
+ sb.append(", ").append(this.getMessageFromBundle("SIZE")).append(product.getProductSize()); //NOI18N
+ }
+
+ // Add price
+ sb.append(" ("); //NOI18N
+ sb.append(this.localizationController.formatCurrency(product.getProductGrossPrice().floatValue()));
+ sb.append(" "); //NOI18N
+ sb.append(product.getProductCurrencyCode());
+ sb.append(")"); //NOI18N
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Returns the category's i18n string translated. If null is provided, an
+ * empty string is returned.
+ * <p>
+ * @param category Product category instance
+ * <p>
+ * @return Category's i18n string translation
+ */
+ public String renderProductCategory (final Category category) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(10);
+
+ // Is a category set?
+ if (category instanceof Category) {
+ // Add title
+ sb.append(this.getMessageFromBundle(category.getCategoryI18nKey()));
+
+ // Is a parent category set?
+ if (category.getParentCategory() instanceof Category) {
+ // Then add it in braces, too
+ sb.append(" ("); //NOI18N
+ sb.append(this.getMessageFromBundle(category.getParentCategory().getCategoryI18nKey()));
+ sb.append(")"); //NOI18N
+ }
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2018 Free Software Foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jfinancials.beans.helper.product;
+
+import java.io.Serializable;
+
+/**
+ * An interface for product bean helper
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface FinancialsProductWebViewHelperController extends Serializable {
+
+}
>
<f:converter converterId="ProductCategoryConverter" />
<f:selectItem itemValue="#{null}" itemLabel="#{msg.PLEASE_SELECT}" noSelectionOption="true" itemDisabled="true" />
- <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{beanHelper.renderProductCategory(category)}" />
+ <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{productBeanHelper.renderProductCategory(category)}" />
</p:selectOneMenu>
<p:outputLabel for="productI18nKey" value="#{project.ADMIN_ENTER_GENERIC_PRODUCT_I18N_KEY}" />
>
<f:converter converterId="ProductCategoryConverter" />
<f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
- <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{beanHelper.renderProductCategory(category)}" />
+ <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{productBeanHelper.renderProductCategory(category)}" />
</p:selectOneMenu>
<p:outputLabel for="categoryI18nKey" value="#{project.ADMIN_ENTER_CATEGORY_I18N_KEY}" />
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+ xmlns:h="http://xmlns.jcp.org/jsf/html"
+ xmlns:f="http://xmlns.jcp.org/jsf/core"
+ xmlns:p="http://primefaces.org/ui"
+ >
+
+ <ui:define name="metadata">
+ <f:metadata>
+ <f:viewParam id="productId" name="productId" value="#{productBeanHelper.product}" converter="GenericProductConverter" required="true" requiredMessage="#{project.ERROR_PARAMETER_PRODUCT_ID_NOT_SET}" converterMessage="#{project.PARAMETER_PRODUCT_ID_INVALID}" />
+ <f:viewAction onPostback="true" action="#{productBeanHelper.notifyControllerProductConverted()}" />
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="document_admin_title">
+ <h:outputText value="#{project.PAGE_TITLE_ADMIN_GENERIC_PRODUCT_DELETE}" />
+ </ui:define>
+
+ <ui:define name="content_header">
+ <h:outputText value="#{project.CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_DELETE}" />
+ </ui:define>
+
+ <ui:define name="content">
+ <p:message for="productId" showSummary="true" />
+ <!-- @TODO Here goes your content. //-->
+ </ui:define>
+</ui:composition>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+ xmlns:h="http://xmlns.jcp.org/jsf/html"
+ xmlns:f="http://xmlns.jcp.org/jsf/core"
+ xmlns:p="http://primefaces.org/ui"
+ >
+
+ <ui:define name="metadata">
+ <f:metadata>
+ <f:viewParam id="productId" name="productId" value="#{productBeanHelper.product}" converter="GenericProductConverter" required="true" requiredMessage="#{project.ERROR_PARAMETER_PRODUCT_ID_NOT_SET}" converterMessage="#{project.PARAMETER_PRODUCT_ID_INVALID}" />
+ <f:viewAction onPostback="true" action="#{productBeanHelper.notifyControllerProductConverted()}" />
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="document_admin_title">
+ <h:outputText value="#{project.PAGE_TITLE_ADMIN_GENERIC_PRODUCT_EDIT}" />
+ </ui:define>
+
+ <ui:define name="content_header">
+ <h:outputText value="#{project.CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_EDIT}" />
+ </ui:define>
+
+ <ui:define name="content">
+ <p:message for="productId" showSummary="true" />
+ <!-- @TODO Here goes your content. //-->
+ </ui:define>
+</ui:composition>
title="#{project.FILTER_BY_MULTIPLE_PRODUCT_CATEGORIES_TITLE}"
>
<f:converter converterId="ProductCategoryConverter" />
- <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{beanHelper.renderProductCategory(category)}" />
+ <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{productBeanHelper.renderProductCategory(category)}" />
</p:selectCheckboxMenu>
</f:facet>
</p:dialog>
</h:form>
- <h:form>
+ <h:form id="form-add-product">
<p:panelGrid columns="1" styleClass="table table-full" layout="grid">
<f:facet name="header">
<h:outputText value="#{project.ADMIN_ADD_GENERIC_PRODUCT_TITLE}" />
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<ui:composition template="/WEB-INF/templates/admin/admin_base.tpl"
+ xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+ xmlns:h="http://xmlns.jcp.org/jsf/html"
+ xmlns:f="http://xmlns.jcp.org/jsf/core"
+ xmlns:p="http://primefaces.org/ui"
+ >
+
+ <ui:define name="metadata">
+ <f:metadata>
+ <f:viewParam id="productId" name="productId" value="#{productBeanHelper.product}" converter="GenericProductConverter" required="true" requiredMessage="#{project.ERROR_PARAMETER_PRODUCT_ID_NOT_SET}" converterMessage="#{project.PARAMETER_PRODUCT_ID_INVALID}" />
+ <f:viewAction onPostback="true" action="#{productBeanHelper.notifyControllerProductConverted()}" />
+ </f:metadata>
+ </ui:define>
+
+ <ui:define name="document_admin_title">
+ <h:outputText value="#{project.PAGE_TITLE_ADMIN_SHOW_GENERIC_PRODUCT}" />
+ </ui:define>
+
+ <ui:define name="content_header">
+ <h:outputText value="#{project.CONTENT_TITLE_ADMIN_SHOW_GENERIC_PRODUCT}" />
+ </ui:define>
+
+ <ui:define name="content">
+ <p:message for="productId" showSummary="true" />
+ <!-- @TODO Here goes your content. //-->
+ </ui:define>
+</ui:composition>
title="#{project.FILTER_BY_MULTIPLE_PRODUCT_CATEGORIES_TITLE}"
>
<f:converter converterId="ProductCategoryConverter" />
- <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{beanHelper.renderProductCategory(category)}" />
+ <f:selectItems value="#{categoryListController.allCategories}" var="category" itemValue="#{category}" itemLabel="#{productBeanHelper.renderProductCategory(category)}" />
</p:selectCheckboxMenu>
</f:facet>
</p:dialog>
</h:form>
- <h:form>
+ <h:form id="form-add-category">
<p:panelGrid columns="1" styleClass="table table-full" layout="grid">
<f:facet name="header">
<h:outputText value="#{project.ADMIN_ADD_PRODUCT_CATEGORY_TITLE}" />