From: Roland Häder Date: Tue, 31 Oct 2017 18:44:33 +0000 (+0100) Subject: Maybe cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=113cd842d0c5b969d5a906f7b95581d8b4f1fff8;p=jfinancials-war.git Maybe cherry-pick: - added mini-links JSF tags for product categories and generic products - added form templates for above again - added views for listing both again - added navigation rules to faces-config.xml - rewrote converter to CDI "lookup" (programatic) which finally let the converter work without any EJB calls - added filtered list for categories and products - added product unit amount and type, like 1 liter - categories and products have now both i18n keys and not direct and untranslateable titles - rewrote + sorted renderGenericProduct() as products now have i18n keys - added menu entries Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java index 3a746f2c..1764c64f 100644 --- a/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java @@ -64,9 +64,9 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp private Boolean categoryShownInStatistics; /** - * Category categoryTitle + * Category categoryI18nKey */ - private String categoryTitle; + private String categoryI18nKey; /** * Parent category @@ -128,21 +128,21 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp } /** - * Getter for category title + * Getter for category i18n key *

- * @return the title + * @return Category i18n key */ - public String getCategoryTitle () { - return this.categoryTitle; + public String getCategoryI18nKey () { + return this.categoryI18nKey; } /** - * Setter for category title + * Setter for category i18n key *

- * @param categoryTitle the title to set + * @param categoryI18nKey Category i18n key */ - public void setCategoryTitle (final String categoryTitle) { - this.categoryTitle = categoryTitle; + public void setCategoryI18nKey (final String categoryI18nKey) { + this.categoryI18nKey = categoryI18nKey; } /** @@ -168,7 +168,7 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp */ private void clear () { // Clear all fields - this.setCategoryTitle(null); + this.setCategoryI18nKey(null); this.setParentCategory(null); } @@ -179,7 +179,7 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp */ private Category createCategoryInstance () { // Create category - final Category category = new ProductCategory(this.getCategoryTitle(), this.getParentCategory(), this.getCategoryShownInStatistics()); + final Category category = new ProductCategory(this.getCategoryI18nKey(), this.getParentCategory(), this.getCategoryShownInStatistics()); // Return it return category; diff --git a/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestBean.java index d9d588c9..e45879a9 100644 --- a/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestBean.java @@ -52,7 +52,7 @@ public class FinancialCategoryWebRequestBean extends BaseFinancialsBean implemen /** * List of all categories */ - private List allCategories; + private final List allCategories; /** * EJB for general category stuff @@ -67,6 +67,11 @@ public class FinancialCategoryWebRequestBean extends BaseFinancialsBean implemen @NamedCache (cacheName = "categoryCache") private Cache categoryCache; + /** + * A list of filtered categories + */ + private List filteredCategories; + /** * Default constructor */ @@ -135,6 +140,26 @@ public class FinancialCategoryWebRequestBean extends BaseFinancialsBean implemen return category; } + /** + * Getter for filtered category list + *

+ * @return Filtered category list + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredCategories () { + return this.filteredCategories; + } + + /** + * Setter for filtered category list + *

+ * @param filteredCategories Filtered category list + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredCategories (final List filteredCategories) { + this.filteredCategories = filteredCategories; + } + /** * Initialization of this bean */ diff --git a/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java index e07d84d9..5592f369 100644 --- a/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java +++ b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java @@ -42,6 +42,7 @@ import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEv import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.product.Product; import org.mxchange.jusercore.events.user.created.CreatedUserEvent; import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; @@ -566,6 +567,31 @@ public class FinancialsWebRequestHelperBean extends BaseFinancialsBean implement return sb.toString(); } + /** + * Returns the product name and price. If null is provided, an empty string + * is returned. + *

+ * @param product Product instance + *

+ * @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) { + // Add name and price + sb.append(product.getProductI18nKey()); + sb.append(" ("); //NOI18N + sb.append(this.localizationController.formatCurrency(product.getProductGrossPrice())); + sb.append(")"); //NOI18N + } + + // Return it + return sb.toString(); + } + /** * Returns the headquarters address. If null is provided, an empty string is * returned. @@ -612,24 +638,29 @@ public class FinancialsWebRequestHelperBean extends BaseFinancialsBean implement } /** - * Returns the product name and price. If null is provided, an empty string - * is returned. + * Returns the category's i18n string translated. If null is provided, an + * empty string is returned. *

- * @param product Product instance + * @param category Product category instance *

- * @return Product name + * @return Category's i18n string translation */ - public String renderProduct (final Product product) { + public String renderProductCategory (final Category category) { // Default is empty string, so let's get started final StringBuilder sb = new StringBuilder(10); - // Is a product set? - if (product instanceof Product) { - // Add name and price - sb.append(product.getProductTitle()); - sb.append(" ("); //NOI18N - sb.append(this.localizationController.formatCurrency(product.getProductGrossPrice())); - sb.append(")"); //NOI18N + // 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 diff --git a/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java index db8058be..842d3b1f 100644 --- a/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java @@ -81,8 +81,8 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl /** * Remote bean for products */ - @EJB (lookup = "java:global/jfinancial-ejb/adminProduct!org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote") - private AdminProductSessionBeanRemote productRemoteBean; + @EJB (lookup = "java:global/jfinancials-ejb/adminProduct!org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote") + private AdminProductSessionBeanRemote adminProductBean; /** * Product's tax rate @@ -90,9 +90,19 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl private Float productTaxRate; /** - * Property productTitle + * I18n key of product */ - private String productTitle; + private String productI18nKey; + + /** + * Product's unit amount + */ + private Float productUnitAmount; + + /** + * Product's unit type + */ + private String productUnitType; /** * Default constructor @@ -116,7 +126,7 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl try { // Call bean - updatedProduct = this.productRemoteBean.addGenericProduct(product); + updatedProduct = this.adminProductBean.addGenericProduct(product); } catch (final ProductAlreadyAddedException ex) { // Continue to throw throw new FaceletException(ex); @@ -130,18 +140,18 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl } /** - * Getter for product's available property + * Getter for product's available *

- * @return Product's available property + * @return Product's available */ public Boolean getProductAvailability () { return this.productAvailability; } /** - * Setter for product's available property + * Setter for product's available *

- * @param productAvailability Product's available property + * @param productAvailability Product's available */ public void setProductAvailability (final Boolean productAvailability) { this.productAvailability = productAvailability; @@ -238,21 +248,57 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl } /** - * Getter for product's title property + * Getter for product's i18n key + *

+ * @return Product's i18n key + */ + public String getProductI18nKey () { + return this.productI18nKey; + } + + /** + * Setter for product's i18n key + *

+ * @param productI18nKey Product's i18n key + */ + public void setProductI18nKey (final String productI18nKey) { + this.productI18nKey = productI18nKey; + } + + /** + * Getter for product's unit amount + *

+ * @return Product's unit amount + */ + public Float getProductUnitAmount () { + return this.productUnitAmount; + } + + /** + * Setter for product's unit amount + *

+ * @param productUnitAmount Product's unit amount + */ + public void setProductUnitAmount (final Float productUnitAmount) { + this.productUnitAmount = productUnitAmount; + } + + /** + * Getter for product's unit type *

- * @return Product's title + * @return Product's unit type */ - public String getProductTitle () { - return this.productTitle; + public String getProductUnitType () { + return this.productUnitType; } /** - * Setter for product's title property + * Setter for product's unit type *

- * @param productTitle Product's title + * @param productUnitType Product's unit type */ - public void setProductTitle (final String productTitle) { - this.productTitle = productTitle; + public void setProductUnitType (final String productUnitType) { + this.productUnitType = productUnitType; } /** @@ -264,7 +310,9 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl this.setProductNetPrice(null); this.setProductTaxRate(null); this.setProductGrossPrice(null); - this.setProductTitle(null); + this.setProductI18nKey(null); + this.setProductUnitAmount(null); + this.setProductUnitType(null); } /** @@ -274,11 +322,13 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl */ private Product createProductInstance () { // Create product instance - final Product product = new GenericProduct(this.getProductTitle(), this.getProductGrossPrice(), this.getProductCurrencyCode(), this.getProductCategory(), this.getProductAvailability()); + final Product product = new GenericProduct(this.getProductI18nKey(), this.getProductGrossPrice(), this.getProductCurrencyCode(), this.getProductCategory(), this.getProductAvailability()); // Set all optional fields product.setProductNetPrice(this.getProductNetPrice()); product.setProductTaxRate(this.getProductTaxRate()); + product.setProductUnitAmount(this.getProductUnitAmount()); + product.setProductUnitType(this.getProductUnitType()); // Return it return product; diff --git a/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestBean.java index 88da637e..635cbe82 100644 --- a/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestBean.java @@ -51,10 +51,15 @@ public class FinancialProductWebRequestBean extends BaseFinancialsBean implement private static final long serialVersionUID = 58_137_539_530_279L; /** - * List for all available products + * List for all products */ private List allProducts; + /** + * List for filtered products + */ + private List filteredProducts; + /** * EJB for general product purposes */ @@ -137,6 +142,26 @@ public class FinancialProductWebRequestBean extends BaseFinancialsBean implement return product; } + /** + * Getter for filtered product list + *

+ * @return Filtered product list + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredProducts () { + return this.filteredProducts; + } + + /** + * Setter for filtered product list + *

+ * @param filteredProducts Filtered product list + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredProducts (final List filteredProducts) { + this.filteredProducts = filteredProducts; + } + /** * Initialization of this bean */ diff --git a/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java b/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java index 7d03212d..5af8d5fd 100644 --- a/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java @@ -16,15 +16,13 @@ */ package org.mxchange.jfinancials.converter.generic_product; -import javax.faces.application.FacesMessage; +import javax.enterprise.inject.spi.CDI; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; +import org.mxchange.jfinancials.beans.product.FinancialProductWebRequestBean; import org.mxchange.jfinancials.beans.product.FinancialProductWebRequestController; import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; import org.mxchange.jproduct.model.product.Product; @@ -46,16 +44,8 @@ public class FinancialsGenericProductConverter implements Converter { public Product getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { // Is the instance there? if (PRODUCT_CONTROLLER == null) { - try { - // Not yet, attempt lookup - final Context initial = new InitialContext(); - - // Lookup EJB - PRODUCT_CONTROLLER = (FinancialProductWebRequestController) initial.lookup("java:global/jfinancials-ejb/productController!org.mxchange.jfinancials.beans.product.FinancialProductWebRequestController"); - } catch (final NamingException ex) { - // Throw it again - throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup backing bean", ex.getMessage()), ex); - } + // Get bean from CDI directly + PRODUCT_CONTROLLER = CDI.current().select(FinancialProductWebRequestBean.class).get(); } // Is the value null or empty? diff --git a/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java b/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java index a1753d0b..983e8b3f 100644 --- a/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java @@ -16,15 +16,12 @@ */ package org.mxchange.jfinancials.converter.product_category; -import javax.faces.application.FacesMessage; +import javax.enterprise.inject.spi.CDI; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; import org.mxchange.jfinancials.beans.category.FinancialCategoryWebRequestBean; import org.mxchange.jfinancials.beans.category.FinancialCategoryWebRequestController; import org.mxchange.jproduct.exceptions.category.CategoryNotFoundException; @@ -47,16 +44,8 @@ public class FinancialsProductCategoryConverter implements Converter { public Category getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { // Is the instance there? if (CATEGORY_CONTROLLER == null) { - try { - // Not yet, attempt lookup - final Context initial = new InitialContext(); - - // Lookup EJB - CATEGORY_CONTROLLER = (FinancialCategoryWebRequestController) initial.lookup(String.format("java:module/%s", FinancialCategoryWebRequestBean.class.getSimpleName())); - } catch (final NamingException ex) { - // Throw it again - throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup backing bean", ex.getMessage()), ex); - } + // Get bean from CDI directly + CATEGORY_CONTROLLER = CDI.current().select(FinancialCategoryWebRequestBean.class).get(); } // Is the value null or empty? diff --git a/web/WEB-INF/faces-config.xml b/web/WEB-INF/faces-config.xml index cab11327..b6471e27 100644 --- a/web/WEB-INF/faces-config.xml +++ b/web/WEB-INF/faces-config.xml @@ -128,6 +128,14 @@ admin_list_company_employee /admin/employee/admin_employee_list.xhtml + + admin_list_category + /admin/category/admin_product_category_list.xhtml + + + admin_list_product + /admin/product/admin_generic_product_list.xhtml + admin_list_user /admin/user/admin_user_list.xhtml @@ -873,6 +881,40 @@ /admin/opening_time/admin_opening_time_delete.xhtml + + /admin/category/admin_product_category_list.xhtml + + admin_show_product_category + /admin/category/admin_product_category_show.xhtml + + + admin_edit_product_category + /admin/category/admin_product_category_edit.xhtml + + + admin_delete_product_category + /admin/category/admin_product_category_delete.xhtml + + + admin_assign_parent_category + /admin/category/admin_product_category_assign_parent.xhtml + + + + /admin/product/admin_generic_product_list.xhtml + + admin_show_generic_product + /admin/product/admin_generic_product_show.xhtml + + + admin_edit_generic_product + /admin/product/admin_generic_product_edit.xhtml + + + admin_delete_generic_product + /admin/product/admin_generic_product_delete.xhtml + + + + http://mxchange.org/jsf/jproduct/links + + outputProductCategoryAdminMiniLinks + This tag renders administrative "mini-links" for given category instance. + resources/tags/admin/links/mini/category/admin_product_category_links.tpl + + category + The product category instance that provides the data for this tag. + true + org.mxchange.jproduct.model.category.Category + + + renderShowLink + Whether to render (default: true) "show product" link. + false + java.langBoolean + + + rendered + Whether this tag is being rendered by JSF engine (default: true). + false + java.lang.Boolean + + + + outputGenericProductAdminMiniLinks + This tag renders administrative "mini-links" for given product instance. + resources/tags/admin/links/mini/product/admin_generic_product_links.tpl + + product + The generic product instance that provides the data for this tag. + true + org.mxchange.jproduct.model.product.Product + + + renderShowLink + Whether to render (default: true) "show product" link. + false + java.langBoolean + + + rendered + Whether this tag is being rendered by JSF engine (default: true). + false + java.lang.Boolean + + + diff --git a/web/WEB-INF/resources/tags/admin/links/mini/category/admin_product_category_links.tpl b/web/WEB-INF/resources/tags/admin/links/mini/category/admin_product_category_links.tpl new file mode 100644 index 00000000..b988c21c --- /dev/null +++ b/web/WEB-INF/resources/tags/admin/links/mini/category/admin_product_category_links.tpl @@ -0,0 +1,33 @@ + + + + +

+ + diff --git a/web/WEB-INF/resources/tags/admin/links/mini/product/admin_generic_product_links.tpl b/web/WEB-INF/resources/tags/admin/links/mini/product/admin_generic_product_links.tpl new file mode 100644 index 00000000..8d748ae2 --- /dev/null +++ b/web/WEB-INF/resources/tags/admin/links/mini/product/admin_generic_product_links.tpl @@ -0,0 +1,33 @@ + + + + + + + diff --git a/web/WEB-INF/templates/admin/category/admin_form_category_data.tpl b/web/WEB-INF/templates/admin/category/admin_form_category_data.tpl new file mode 100644 index 00000000..c4d265cd --- /dev/null +++ b/web/WEB-INF/templates/admin/category/admin_form_category_data.tpl @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/web/WEB-INF/templates/admin/menu/project.tpl b/web/WEB-INF/templates/admin/menu/project.tpl index a5f68a54..887a46b7 100644 --- a/web/WEB-INF/templates/admin/menu/project.tpl +++ b/web/WEB-INF/templates/admin/menu/project.tpl @@ -1,8 +1,6 @@ @@ -10,4 +8,9 @@ + + + + + diff --git a/web/WEB-INF/templates/admin/product/admin_form_product_data.tpl b/web/WEB-INF/templates/admin/product/admin_form_product_data.tpl new file mode 100644 index 00000000..2587060e --- /dev/null +++ b/web/WEB-INF/templates/admin/product/admin_form_product_data.tpl @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/WEB-INF/web.xml b/web/WEB-INF/web.xml index dbce861c..3e85fbc2 100644 --- a/web/WEB-INF/web.xml +++ b/web/WEB-INF/web.xml @@ -30,7 +30,7 @@ Generic custom JSF tags library javax.faces.FACELETS_LIBRARIES - /WEB-INF/widgets.jsf.taglib.xml;/WEB-INF/links.jsf.taglib.xml;/WEB-INF/project-links.jsf.taglib.xml;/WEB-INF/product.jsf.taglib.xml + /WEB-INF/widgets.jsf.taglib.xml;/WEB-INF/links.jsf.taglib.xml;/WEB-INF/project-links.jsf.taglib.xml;/WEB-INF/product.jsf.taglib.xml;/WEB-INF/product-links.jsf.taglib.xml Project stage diff --git a/web/admin/category/admin_product_category_list.xhtml b/web/admin/category/admin_product_category_list.xhtml new file mode 100644 index 00000000..1796183a --- /dev/null +++ b/web/admin/category/admin_product_category_list.xhtml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/web/admin/product/admin_generic_product_list.xhtml b/web/admin/product/admin_generic_product_list.xhtml new file mode 100644 index 00000000..bcaa8190 --- /dev/null +++ b/web/admin/product/admin_generic_product_list.xhtml @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +