]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Product-only:
authorRoland Häder <roland@mxchange.org>
Thu, 20 Dec 2018 11:07:51 +0000 (12:07 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 20 Dec 2018 11:12:33 +0000 (12:12 +0100)
- 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 <roland@mxchange.org>
src/java/org/mxchange/jfinancials/beans/generic_product/action/FinancialAdminGenericProductActionWebViewBean.java
src/java/org/mxchange/jfinancials/beans/product_category/FinancialAdminCategoryWebRequestBean.java
src/java/org/mxchange/jfinancials/validator/generic_product/FinancialsGenericProductValidator.java
web/WEB-INF/product.jsf.taglib.xml
web/WEB-INF/resources/tags/forms/generic_product/admin_form_generic_product_data.tpl
web/admin/generic_product/admin_generic_product_edit.xhtml

index a7c1f30ad4b15011143e5b9ee1232a4dc5eba72d..b0a005bcad9df96aa8e6028b0ef7fdbbd5ac913e 100644 (file)
@@ -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());
index c427ca173273bd6dc7ae6a989fc6b8a3986d46c3..a1531eda137845bbde948872275e8f3e9331d2f8 100644 (file)
@@ -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)
         * <p>
@@ -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;
index 6d165c2f7e83efe9a482c1b601960d4525892a0b..72a7a700695b3df2568f0b87088ad26b53203a43 100644 (file)
@@ -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);
 
index 82a20bcb764436835aed53377040fc3d7325f20d..a699e20858ef323d68bb99b5b3b21970284fd5bc 100644 (file)
@@ -51,5 +51,11 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
                        <!-- @TODO Find an interface for BaseFacesBean and set it here instead -->
                        <type>org.mxchange.jcoreee.bean.faces.BaseFacesBean</type>
                </attribute>
+               <attribute>
+                       <name>allowDuplicates</name>
+                       <description>Whether to allow duplicate i18n keys.</description>
+                       <required>false</required>
+                       <type>java.lang.Boolean</type>
+               </attribute>
        </tag>
 </facelet-taglib>
index bab74b628546dcdb34977eb296f44f124ccc3da2..2b706ae52fdee4ce015773a5cd6199c9e98a1229 100644 (file)
@@ -51,6 +51,7 @@
                                validatorMessage="#{project.ADMIN_ENTERED_PRODUCT_I18N_KEY_ALREADY_ADDED}"
                                >
                                <f:validator validatorId="GenericProductValidator" />
+                               <f:attribute name="allowDuplicates" value="#{allowDuplicates}" />
                        </p:inputText>
 
                        <p:outputLabel for="productNumber" value="#{project.ADMIN_ENTER_GENERIC_PRODUCT_NUMBER}" />
index 4e74068ebcd3774fb76f08c869e3cd52ee8af083..3fd371eec24e47770887f61bcad3e131d71bf822 100644 (file)
@@ -61,6 +61,7 @@
 
                                <product:genericProductForm
                                        targetController="#{adminGenericProductActionController}"
+                                       allowDuplicates="true"
                                        />
 
                                <f:facet name="footer">