From: Roland Häder Date: Thu, 20 Dec 2018 11:07:51 +0000 (+0100) Subject: Product-only: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b3b7485088d24b94a4d0e93c86adf6d703b00e5a;p=jfinancials-war.git Product-only: - implemented allowDuplicates in product i18n key validator (default: FALSE) - added it to product:genericProductForm tag (custom JSF tag) - allowed "duplicates" in edit view, still the generic string validation applies) - parentCategory is optional and must be set "manually" by setter - removed clear() method (which sets NULL to all backing-bean fields/properties (?) - realigned code a bit (createProductInstance()) Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java index a7c1f30a..b0a005bc 100644 --- a/src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java +++ b/src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java @@ -547,7 +547,15 @@ public class FinancialAdminGenericProductActionWebViewBean extends BaseFinancial */ private Product createProductInstance () { // Create product instance - final Product newProduct = new GenericProduct(this.getProductI18nKey(), this.getProductGrossPrice(), this.getProductCurrencyCode(), this.getProductCategory(), this.getProductAvailability(), this.getProductUnitAmount(), this.getProductUnitI18nKey()); + final Product newProduct = new GenericProduct( + this.getProductI18nKey(), + this.getProductGrossPrice(), + this.getProductCurrencyCode(), + this.getProductCategory(), + this.getProductAvailability(), + this.getProductUnitAmount(), + this.getProductUnitI18nKey() + ); // Set all optional fields newProduct.setProductAgeGroup(this.getProductAgeGroup()); diff --git a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestBean.java index c427ca17..a1531eda 100644 --- a/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestBean.java @@ -116,9 +116,6 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp // Fire event this.categoryAddedEvent.fire(new CategoryAddedEvent(updatedCategory)); - - // Unset all older values - this.clear(); } /** @@ -175,15 +172,6 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp this.parentCategory = parentCategory; } - /** - * Clears this bean (example: when category has been added) - */ - private void clear () { - // Clear all fields - this.setCategoryI18nKey(null); - this.setParentCategory(null); - } - /** * Creates a category instance with all fields (except primary key) *

@@ -191,7 +179,10 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp */ private Category createCategoryInstance () { // Create category - final Category category = new ProductCategory(this.getCategoryI18nKey(), this.getParentCategory(), this.getCategoryShownInStatistics()); + final Category category = new ProductCategory(this.getCategoryI18nKey(), this.getCategoryShownInStatistics()); + + // Set all optional fields + category.setParentCategory(this.getParentCategory()); // Return it return category; diff --git a/src/java/org/mxchange/jfinancials/validator/generic_product/FinancialsGenericProductValidator.java b/src/java/org/mxchange/jfinancials/validator/generic_product/FinancialsGenericProductValidator.java index 6d165c2f..72a7a700 100644 --- a/src/java/org/mxchange/jfinancials/validator/generic_product/FinancialsGenericProductValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/generic_product/FinancialsGenericProductValidator.java @@ -49,7 +49,7 @@ public class FinancialsGenericProductValidator extends BaseStringValidator { @Override public void validate (final FacesContext context, final UIComponent component, final Object productI18nKey) throws ValidatorException { // The required field - final String[] requiredFields = {"categoryI18nKey"}; //NOI18N + final String[] requiredFields = {"productI18nKey"}; //NOI18N // Pre-validate it super.preValidate(context, component, productI18nKey, requiredFields, Boolean.FALSE); @@ -60,8 +60,26 @@ public class FinancialsGenericProductValidator extends BaseStringValidator { PRODUCT_LIST_CONTROLLER = CDI.current().select(FinancialsProductListWebViewBean.class).get(); } + // Don't allow duplicates by default + Boolean allowDuplicates = Boolean.FALSE; + + // Is attribute "allowEmptyRequiredData" set? + if (component.getAttributes().containsKey("allowDuplicates")) { //NOI18N + // Get attribute + final Object attribute = component.getAttributes().get("allowDuplicates"); //NOI18N + + // Make sure, it is Boolean as no String is accepted anymore + if (!(attribute instanceof String)) { + // Not valid attribute, please use "true" or "false" (default) + throw new IllegalArgumentException("allowDuplicates must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N + } + + // Securely cast it + allowDuplicates = Boolean.parseBoolean((String) attribute); + } + // Check, if the name has already been used - if (PRODUCT_LIST_CONTROLLER.isProductI18nKeyAdded((String) productI18nKey)) { + if (!allowDuplicates && PRODUCT_LIST_CONTROLLER.isProductI18nKeyAdded((String) productI18nKey)) { // Create message final String message = MessageFormat.format("I18n key {0} is already used. Please type an other.", productI18nKey); diff --git a/web/WEB-INF/product.jsf.taglib.xml b/web/WEB-INF/product.jsf.taglib.xml index 82a20bcb..a699e208 100644 --- a/web/WEB-INF/product.jsf.taglib.xml +++ b/web/WEB-INF/product.jsf.taglib.xml @@ -51,5 +51,11 @@ along with this program. If not, see . org.mxchange.jcoreee.bean.faces.BaseFacesBean + + allowDuplicates + Whether to allow duplicate i18n keys. + false + java.lang.Boolean + diff --git a/web/WEB-INF/resources/tags/forms/generic_product/admin_form_generic_product_data.tpl b/web/WEB-INF/resources/tags/forms/generic_product/admin_form_generic_product_data.tpl index bab74b62..2b706ae5 100644 --- a/web/WEB-INF/resources/tags/forms/generic_product/admin_form_generic_product_data.tpl +++ b/web/WEB-INF/resources/tags/forms/generic_product/admin_form_generic_product_data.tpl @@ -51,6 +51,7 @@ validatorMessage="#{project.ADMIN_ENTERED_PRODUCT_I18N_KEY_ALREADY_ADDED}" > + diff --git a/web/admin/generic_product/admin_generic_product_edit.xhtml b/web/admin/generic_product/admin_generic_product_edit.xhtml index 4e74068e..3fd371ee 100644 --- a/web/admin/generic_product/admin_generic_product_edit.xhtml +++ b/web/admin/generic_product/admin_generic_product_edit.xhtml @@ -61,6 +61,7 @@