*/
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
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);
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-@FacesValidator(value = "ProductCategoryValidator")
+@FacesValidator (value = "ProductCategoryValidator")
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
}
// 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);
+++ /dev/null
-<?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>
--- /dev/null
+<?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>
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
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}" />
+++ /dev/null
-<?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>
--- /dev/null
+<?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>
<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>
<ui:define name="metadata">
<f:metadata>
<f:viewParam
- id="productId"
name="productId"
value="#{adminGenericProductActionController.currentProduct}"
converter="GenericProductConverter"
<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">
<ui:define name="metadata">
<f:metadata>
<f:viewParam
- id="productId"
name="productId"
value="#{adminGenericProductActionController.currentProduct}"
converter="GenericProductConverter"
<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">
<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">