]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Product-only:
authorRoland Häder <roland@mxchange.org>
Wed, 28 Sep 2022 17:10:11 +0000 (19:10 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 28 Sep 2022 17:10:11 +0000 (19:10 +0200)
- introduced validator JSF tags for product and category
- edit views must bypass duplicate i18n key check
- ops, had to rename wrongly named template

13 files changed:
src/java/org/mxchange/jfinancials/validator/generic_product/FinancialsGenericProductValidator.java
src/java/org/mxchange/jfinancials/validator/product_category/FinancialsProductCategoryValidator.java
web/WEB-INF/product-links.jsf.taglib.xml [deleted file]
web/WEB-INF/product.jsf.taglib.xml [new file with mode: 0644]
web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl
web/WEB-INF/templates/admin/product_category/admin_form_generic_product_data.tpl [deleted file]
web/WEB-INF/templates/admin/product_category/admin_form_product_category_data.tpl [new file with mode: 0644]
web/WEB-INF/web.xml
web/admin/generic_product/admin_generic_product_delete.xhtml
web/admin/generic_product/admin_generic_product_edit.xhtml
web/admin/generic_product/admin_generic_product_show.xhtml
web/admin/product_category/admin_product_category_edit.xhtml
web/admin/product_category/admin_product_category_list.xhtml

index 97126044fa7ed6db838118338e9fa33605bf5977..4a18fb55e050c5113a8ca0e3bfa9ebfa576c6cd2 100644 (file)
@@ -46,6 +46,28 @@ public class FinancialsGenericProductValidator extends BaseStringValidator {
         */
        private static final long serialVersionUID = 1_086_256_763_716_450L;
 
+       /**
+        * Whether bypass duplicate i18n key check
+        */
+       private Boolean bypassDuplicateI18nKey;
+
+       /**
+        * Default constructor
+        */
+       public FinancialsGenericProductValidator () {
+               // Set allowEmpty to FALSE by default
+               this.bypassDuplicateI18nKey = Boolean.FALSE;
+       }
+
+       /**
+        * Setter for bypassDuplicateI18nKey flag
+        * <p>
+        * @param bypassDuplicateI18nKey Whether to bypass i18n key duplicate-check
+        */
+       public void setBypassDuplicateI18nKey (final Boolean bypassDuplicateI18nKey) {
+               this.bypassDuplicateI18nKey = bypassDuplicateI18nKey;
+       }
+
        @Override
        public void validate (final FacesContext context, final UIComponent component, final Object productI18nKey) throws ValidatorException {
                // The required field
@@ -60,26 +82,8 @@ 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 (!allowDuplicates && PRODUCT_LIST_CONTROLLER.isProductI18nKeyAdded((String) productI18nKey)) {
+               if (!this.bypassDuplicateI18nKey && PRODUCT_LIST_CONTROLLER.isProductI18nKeyAdded((String) productI18nKey)) {
                        // Create message
                        final String message = MessageFormat.format("I18n key {0} is already used. Please type an other.", productI18nKey);
 
index d85edcde7d838a9255b78a5c94c0c9ee8ac7eb63..307fbadb400e948d02beea70c65ae1a9def442ea 100644 (file)
@@ -33,7 +33,7 @@ import org.mxchange.jfinancials.beans.product_category.list.FinancialsCategoryLi
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@FacesValidator(value = "ProductCategoryValidator")
+@FacesValidator (value = "ProductCategoryValidator")
 public class FinancialsProductCategoryValidator extends BaseStringValidator {
 
        /**
@@ -46,6 +46,28 @@ public class FinancialsProductCategoryValidator extends BaseStringValidator {
         */
        private static final long serialVersionUID = 1_086_256_763_716_450L;
 
+       /**
+        * Whether bypass duplicate i18n key check
+        */
+       private Boolean bypassDuplicateI18nKey;
+
+       /**
+        * Default constructor
+        */
+       public FinancialsProductCategoryValidator () {
+               // Set allowEmpty to FALSE by default
+               this.bypassDuplicateI18nKey = Boolean.FALSE;
+       }
+
+       /**
+        * Setter for bypassDuplicateI18nKey flag
+        * <p>
+        * @param bypassDuplicateI18nKey Whether to bypass i18n key duplicate-check
+        */
+       public void setBypassDuplicateI18nKey (final Boolean bypassDuplicateI18nKey) {
+               this.bypassDuplicateI18nKey = bypassDuplicateI18nKey;
+       }
+
        @Override
        public void validate (final FacesContext context, final UIComponent component, final Object categoryI18nKey) throws ValidatorException {
                // The required field
@@ -61,7 +83,7 @@ public class FinancialsProductCategoryValidator extends BaseStringValidator {
                }
 
                // Check, if the name has already been used
-               if (CATEGORY_LIST_CONTROLLER.isCategoryI18nKeyAdded((String) categoryI18nKey)) {
+               if (!this.bypassDuplicateI18nKey && CATEGORY_LIST_CONTROLLER.isCategoryI18nKeyAdded((String) categoryI18nKey)) {
                        // Create message
                        final String message = MessageFormat.format("I18n key {0} is already used. Please type an other.", categoryI18nKey);
 
diff --git a/web/WEB-INF/product-links.jsf.taglib.xml b/web/WEB-INF/product-links.jsf.taglib.xml
deleted file mode 100644 (file)
index 56a8ae7..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-Copyright (C) 2017 - 2022 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/>.
--->
-<facelet-taglib
-       version="2.2"
-       xmlns="http://xmlns.jcp.org/xml/ns/javaee"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"
->
-       <namespace>http://mxchange.org/jsf/jproduct/links</namespace>
-</facelet-taglib>
diff --git a/web/WEB-INF/product.jsf.taglib.xml b/web/WEB-INF/product.jsf.taglib.xml
new file mode 100644 (file)
index 0000000..7b36b25
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (C) 2017 - 2022 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/>.
+-->
+<facelet-taglib
+       version="2.2"
+       xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"
+>
+       <namespace>http://mxchange.org/jsf/product/validators</namespace>
+       <tag>
+               <tag-name>genericProductValidator</tag-name>
+               <validator>
+                       <validator-id>GenericProductValidator</validator-id>
+               </validator>
+               <attribute>
+                       <description>Whether check for duplicate i18n keys is bypassed which makes only sense in "edit" views.</description>
+                       <name>bypassDuplicateI18nKey</name>
+                       <type>java.lang.Boolean</type>
+                       <required>false</required>
+               </attribute>
+       </tag>
+       <tag>
+               <tag-name>productCategoryValidator</tag-name>
+               <validator>
+                       <validator-id>ProductCategoryValidator</validator-id>
+               </validator>
+               <attribute>
+                       <description>Whether check for duplicate i18n keys is bypassed which makes only sense in "edit" views.</description>
+                       <name>bypassDuplicateI18nKey</name>
+                       <type>java.lang.Boolean</type>
+                       <required>false</required>
+               </attribute>
+       </tag>
+</facelet-taglib>
index 07fc7bd804394b09e7f0c89826403aa353a4b916..503d4c6114efd68c3218a2200fed367723b12926 100644 (file)
@@ -4,6 +4,7 @@
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
        xmlns:p="http://primefaces.org/ui"
+       xmlns:validator="http://mxchange.org/jsf/product/validators"
        >
 
        <p:fieldset
@@ -54,8 +55,7 @@
                                title="#{product.ADMIN_ENTER_GENERIC_PRODUCT_I18N_KEY_TITLE}"
                                validatorMessage="#{product.ADMIN_ENTERED_PRODUCT_I18N_KEY_ALREADY_ADDED}"
                                >
-                               <f:validator validatorId="GenericProductValidator" />
-                               <f:attribute name="allowDuplicates" value="#{allowDuplicates}" />
+                               <validator:genericProductValidator bypassDuplicateI18nKey="#{bypassDuplicateI18nKey}" />
                        </p:inputText>
 
                        <p:outputLabel for="productNumber" value="#{product.ADMIN_ENTER_GENERIC_PRODUCT_NUMBER}" />
diff --git a/web/WEB-INF/templates/admin/product_category/admin_form_generic_product_data.tpl b/web/WEB-INF/templates/admin/product_category/admin_form_generic_product_data.tpl
deleted file mode 100644 (file)
index b658e8e..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<ui:composition
-       xmlns="http://www.w3.org/1999/xhtml"
-       xmlns:f="http://xmlns.jcp.org/jsf/core"
-       xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
-       xmlns:p="http://primefaces.org/ui"
-       >
-
-       <p:fieldset legend="#{product.ADMIN_PRODUCT_CATEGORY_DATA_LEGEND}">
-               <p:panelGrid
-                       layout="grid"
-                       columns="2"
-                       columnClasses="ui-grid-col-4,ui-grid-col-8"
-                       styleClass="ui-noborder"
-                       >
-                       <p:outputLabel for="parentCategory" value="#{product.ADMIN_ASSIGN_PARENT_PRODUCT_CATEGORY}" />
-                       <p:selectOneMenu
-                               id="parentCategory"
-                               value="#{adminProductCategoryActionController.parentCategory}"
-                               filter="true"
-                               filterMatchMode="contains"
-                               title="#{product.ADMIN_ASSIGN_PARENT_PRODUCT_CATEGORY_TITLE}"
-                               >
-
-                               <f:converter converterId="ProductCategoryConverter" />
-
-                               <f:selectItem
-                                       itemValue="#{null}"
-                                       itemLabel="#{msg.NONE_SELECTED}"
-                                       />
-
-                               <f:selectItems
-                                       value="#{productCategoryListController.allProductCategories}"
-                                       var="category"
-                                       itemValue="#{category}"
-                                       itemLabel="#{productBeanHelper.renderProductCategory(category)}"
-                                       />
-                       </p:selectOneMenu>
-
-                       <p:outputLabel for="categoryI18nKey" value="#{product.ADMIN_ENTER_CATEGORY_I18N_KEY}" />
-                       <p:inputText
-                               id="categoryI18nKey"
-                               value="#{adminProductCategoryActionController.categoryI18nKey}"
-                               maxlength="255"
-                               required="true"
-                               requiredMessage="#{product.ADMIN_CATEGORY_I18N_KEY_REQUIRED}"
-                               title="#{product.ADMIN_ENTER_CATEGORY_I18N_KEY_TITLE}"
-                               validatorMessage="#{product.ADMIN_ENTERED_CATEGORY_I18N_KEY_ALREADY_ADDED}"
-                               >
-                               <f:validator validatorId="ProductCategoryValidator" />
-                       </p:inputText>
-
-                       <p:outputLabel for="categoryShownInStatistics" value="#{product.ADMIN_ENABLE_CATEGORY_IN_STATISTICS}" />
-                       <p:selectBooleanCheckbox
-                               id="categoryShownInStatistics"
-                               value="#{adminProductCategoryActionController.categoryShownInStatistics}"
-                               required="true"
-                               requiredMessage="#{product.ADMIN_ENABLE_CATEGORY_IN_STATISTICS_REQUIRED}"
-                               title="#{product.ADMIN_ENABLE_CATEGORY_IN_STATISTICS_TITLE}"
-                               />
-               </p:panelGrid>
-       </p:fieldset>
-</ui:composition>
diff --git a/web/WEB-INF/templates/admin/product_category/admin_form_product_category_data.tpl b/web/WEB-INF/templates/admin/product_category/admin_form_product_category_data.tpl
new file mode 100644 (file)
index 0000000..9ba4fdb
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<ui:composition
+       xmlns="http://www.w3.org/1999/xhtml"
+       xmlns:f="http://xmlns.jcp.org/jsf/core"
+       xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
+       xmlns:p="http://primefaces.org/ui"
+       xmlns:validator="http://mxchange.org/jsf/product/validators"
+       >
+
+       <p:fieldset legend="#{product.ADMIN_PRODUCT_CATEGORY_DATA_LEGEND}">
+               <p:panelGrid
+                       layout="grid"
+                       columns="2"
+                       columnClasses="ui-grid-col-4,ui-grid-col-8"
+                       styleClass="ui-noborder"
+                       >
+                       <p:outputLabel for="parentCategory" value="#{product.ADMIN_ASSIGN_PARENT_PRODUCT_CATEGORY}" />
+                       <p:selectOneMenu
+                               id="parentCategory"
+                               value="#{adminProductCategoryActionController.parentCategory}"
+                               filter="true"
+                               filterMatchMode="contains"
+                               title="#{product.ADMIN_ASSIGN_PARENT_PRODUCT_CATEGORY_TITLE}"
+                               >
+
+                               <f:converter converterId="ProductCategoryConverter" />
+
+                               <f:selectItem
+                                       itemValue="#{null}"
+                                       itemLabel="#{msg.NONE_SELECTED}"
+                                       />
+
+                               <f:selectItems
+                                       value="#{productCategoryListController.allProductCategories}"
+                                       var="category"
+                                       itemValue="#{category}"
+                                       itemLabel="#{productBeanHelper.renderProductCategory(category)}"
+                                       />
+                       </p:selectOneMenu>
+
+                       <p:outputLabel for="categoryI18nKey" value="#{product.ADMIN_ENTER_CATEGORY_I18N_KEY}" />
+                       <p:inputText
+                               id="categoryI18nKey"
+                               value="#{adminProductCategoryActionController.categoryI18nKey}"
+                               maxlength="255"
+                               required="true"
+                               requiredMessage="#{product.ADMIN_CATEGORY_I18N_KEY_REQUIRED}"
+                               title="#{product.ADMIN_ENTER_CATEGORY_I18N_KEY_TITLE}"
+                               validatorMessage="#{product.ADMIN_ENTERED_CATEGORY_I18N_KEY_ALREADY_ADDED}"
+                               >
+                               <validator:genericProductValidator bypassDuplicateI18nKey="#{bypassDuplicateI18nKey}" />
+                       </p:inputText>
+
+                       <p:outputLabel for="categoryShownInStatistics" value="#{product.ADMIN_ENABLE_CATEGORY_IN_STATISTICS}" />
+                       <p:selectBooleanCheckbox
+                               id="categoryShownInStatistics"
+                               value="#{adminProductCategoryActionController.categoryShownInStatistics}"
+                               required="true"
+                               requiredMessage="#{product.ADMIN_ENABLE_CATEGORY_IN_STATISTICS_REQUIRED}"
+                               title="#{product.ADMIN_ENABLE_CATEGORY_IN_STATISTICS_TITLE}"
+                               />
+               </p:panelGrid>
+       </p:fieldset>
+</ui:composition>
index 07e266c5ac431b56ede22b9a0e6471c66cef886f..f6bb5d2a93aa98e0d672596134058eedb163d43a 100644 (file)
@@ -30,7 +30,7 @@
        <context-param>
                <description>Generic custom JSF tags library</description>
                <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
-               <param-value>/WEB-INF/widgets.jsf.taglib.xml;/WEB-INF/validators.jsf.taglib.xml;/WEB-INF/links.jsf.taglib.xml;/WEB-INF/project-links.jsf.taglib.xml;;/WEB-INF/product-links.jsf.taglib.xml</param-value>
+               <param-value>/WEB-INF/widgets.jsf.taglib.xml;/WEB-INF/validators.jsf.taglib.xml;/WEB-INF/links.jsf.taglib.xml;/WEB-INF/project-links.jsf.taglib.xml;;/WEB-INF/product.jsf.taglib.xml</param-value>
        </context-param>
        <context-param>
                <description>Project stage</description>
index 75837d77139ae635834f5cfde3734b1effed30f4..a19da9e29c0c14f7ff10e3660d552ed4a229c3c4 100644 (file)
@@ -11,7 +11,6 @@
        <ui:define name="metadata">
                <f:metadata>
                        <f:viewParam
-                               id="productId"
                                name="productId"
                                value="#{adminGenericProductActionController.currentProduct}"
                                converter="GenericProductConverter"
index 0b01325c7aa261de194267f797d7de377288c1b3..90a562c296af453c7efd389fcddebf652867541e 100644 (file)
@@ -57,7 +57,9 @@
                                        <h:outputText value="#{product.ADMIN_EDIT_GENERIC_PRODUCT_MINIMUM_DATA}" />
                                </h:panelGroup>
 
-                               <ui:include src="/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl" />
+                               <ui:include src="/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl">
+                                       <ui:param name="bypassDuplicateI18nKey" value="true" />
+                               </ui:include>
 
                                <f:facet name="footer">
                                        <p:panelGrid columns="2" layout="grid">
index 412f69bb386a4a35580f258c3d1d054f305b7c23..e0e8fc3068a431e1b14a61909c495575130e34f5 100644 (file)
@@ -11,7 +11,6 @@
        <ui:define name="metadata">
                <f:metadata>
                        <f:viewParam
-                               id="productId"
                                name="productId"
                                value="#{adminGenericProductActionController.currentProduct}"
                                converter="GenericProductConverter"
index e7934c144091b4eff92effc1f156acb5cac82ef6..ceeaa0dbe74d02ba27f0fb5df85b82a3f1901908 100644 (file)
@@ -57,7 +57,9 @@
                                        <h:outputText value="#{product.ADMIN_EDIT_PRODUCT_CATEGORY_MINIMUM_DATA}" />
                                </h:panelGroup>
 
-                               <ui:include src="/WEB-INF/templates/admin/product_category/admin_form_generic_product_data.tpl" />
+                               <ui:include src="/WEB-INF/templates/admin/product_category/admin_form_product_category_data.tpl">
+                                       <ui:param name="bypassDuplicateI18nKey" value="true" />
+                               </ui:include>
 
                                <f:facet name="footer">
                                        <p:panelGrid columns="2" layout="grid">
index ccbcdcba253de7fc5e2e165058642e0e4968643c..459059261be8e41c49dab3f95944c6c0db4a3655 100644 (file)
                                        <h:outputText value="#{product.ADMIN_ADD_PRODUCT_CATEGORY_MINIMUM_DATA}" />
                                </h:panelGroup>
 
-                               <ui:include src="/WEB-INF/templates/admin/product_category/admin_form_generic_product_data.tpl" />
+                               <ui:include src="/WEB-INF/templates/admin/product_category/admin_form_product_category_data.tpl" />
 
                                <f:facet name="footer">
                                        <p:panelGrid columns="2" layout="grid">