From: Roland Häder Date: Thu, 23 Apr 2020 01:10:30 +0000 (+0200) Subject: Product-only: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=85f229129793c770879adc6bb937a379f56fe005;p=jfinancials-war.git Product-only: - moved converter to deeper packages - some renderFoo() methods have extra parameters, added Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java b/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java deleted file mode 100644 index cfb67b04..00000000 --- a/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 . - */ -package org.mxchange.jfinancials.converter.generic_product; - -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 org.mxchange.jfinancials.beans.generic_product.list.FinancialsProductListWebViewBean; -import org.mxchange.jfinancials.beans.generic_product.list.FinancialsProductListWebViewController; -import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; -import org.mxchange.jproduct.model.product.Product; - -/** - * Converter for product id <-> valid product instance - *

- * @author Roland Häder - */ -@FacesConverter ("GenericProductConverter") -public class FinancialsGenericProductConverter implements Converter { - - /** - * Product backing bean - */ - private static FinancialsProductListWebViewController PRODUCT_LIST_CONTROLLER; - - @Override - public Product getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the instance there? - if (null == PRODUCT_LIST_CONTROLLER) { - // Get bean from CDI directly - PRODUCT_LIST_CONTROLLER = CDI.current().select(FinancialsProductListWebViewBean.class).get(); - } - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Return null - return null; - } - - // Init instance - Product product = null; - - try { - // Try to parse the value as long - final Long productId = Long.valueOf(submittedValue); - - // Try to get user instance from it - product = PRODUCT_LIST_CONTROLLER.findProductById(productId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final ProductNotFoundException ex) { - // Debug message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N - } - - // Return it - return product; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Product value) { - // Is the object null? - if ((null == value) || (String.valueOf(value).isEmpty())) { - // Is null - return ""; //NOI18N - } - - // Return id number - return String.valueOf(value.getProductId()); - } - -} diff --git a/src/java/org/mxchange/jfinancials/converter/product/generic_product/FinancialsGenericProductConverter.java b/src/java/org/mxchange/jfinancials/converter/product/generic_product/FinancialsGenericProductConverter.java new file mode 100644 index 00000000..ba66faf4 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/product/generic_product/FinancialsGenericProductConverter.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2016 - 2020 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 . + */ +package org.mxchange.jfinancials.converter.product.generic_product; + +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 org.mxchange.jfinancials.beans.generic_product.list.FinancialsProductListWebViewBean; +import org.mxchange.jfinancials.beans.generic_product.list.FinancialsProductListWebViewController; +import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; +import org.mxchange.jproduct.model.product.Product; + +/** + * Converter for product id <-> valid product instance + *

+ * @author Roland Häder + */ +@FacesConverter ("GenericProductConverter") +public class FinancialsGenericProductConverter implements Converter { + + /** + * Product backing bean + */ + private static FinancialsProductListWebViewController PRODUCT_LIST_CONTROLLER; + + @Override + public Product getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + Product product = null; + + // Is the instance there? + if (null == PRODUCT_LIST_CONTROLLER) { + // Get bean from CDI directly + PRODUCT_LIST_CONTROLLER = CDI.current().select(FinancialsProductListWebViewBean.class).get(); + } + + try { + // Try to parse the value as long + final Long productId = Long.valueOf(submittedValue); + + // Try to get user instance from it + product = PRODUCT_LIST_CONTROLLER.findProductById(productId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final ProductNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N + } + + // Return it + return product; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Product value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getProductId()); + } + +} diff --git a/src/java/org/mxchange/jfinancials/converter/product/product_category/FinancialsProductCategoryConverter.java b/src/java/org/mxchange/jfinancials/converter/product/product_category/FinancialsProductCategoryConverter.java new file mode 100644 index 00000000..e6484e3b --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/product/product_category/FinancialsProductCategoryConverter.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2016 - 2020 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 . + */ +package org.mxchange.jfinancials.converter.product.product_category; + +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 org.mxchange.jfinancials.beans.product_category.list.FinancialsCategoryListWebViewBean; +import org.mxchange.jfinancials.beans.product_category.list.FinancialsCategoryListWebViewController; +import org.mxchange.jproduct.exceptions.category.CategoryNotFoundException; +import org.mxchange.jproduct.model.category.Category; + +/** + * Converter for category id <-> valid category instance + *

+ * @author Roland Häder + */ +@FacesConverter ("ProductCategoryConverter") +public class FinancialsProductCategoryConverter implements Converter { + + /** + * Category backing bean + */ + private static FinancialsCategoryListWebViewController CATEGORY_LIST_CONTROLLER; + + @Override + public Category getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + Category category = null; + + // Is the instance there? + if (null == CATEGORY_LIST_CONTROLLER) { + // Get bean from CDI directly + CATEGORY_LIST_CONTROLLER = CDI.current().select(FinancialsCategoryListWebViewBean.class).get(); + } + + try { + // Try to parse the value as long + final Long categoryId = Long.valueOf(submittedValue); + + // Try to get user instance from it + category = CATEGORY_LIST_CONTROLLER.findCategoryById(categoryId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final CategoryNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N + } + + // Return it + return category; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Category value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getCategoryId()); + } + +} diff --git a/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java b/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java deleted file mode 100644 index 8d4cb67e..00000000 --- a/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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 . - */ -package org.mxchange.jfinancials.converter.product_category; - -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 org.mxchange.jfinancials.beans.product_category.list.FinancialsCategoryListWebViewBean; -import org.mxchange.jfinancials.beans.product_category.list.FinancialsCategoryListWebViewController; -import org.mxchange.jproduct.exceptions.category.CategoryNotFoundException; -import org.mxchange.jproduct.model.category.Category; - -/** - * Converter for category id <-> valid category instance - *

- * @author Roland Häder - */ -@FacesConverter ("ProductCategoryConverter") -public class FinancialsProductCategoryConverter implements Converter { - - /** - * Category backing bean - */ - private static FinancialsCategoryListWebViewController CATEGORY_LIST_CONTROLLER; - - @Override - public Category getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the instance there? - if (null == CATEGORY_LIST_CONTROLLER) { - // Get bean from CDI directly - CATEGORY_LIST_CONTROLLER = CDI.current().select(FinancialsCategoryListWebViewBean.class).get(); - } - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Return null - return null; - } - - // Init instance - Category category = null; - - try { - // Try to parse the value as long - final Long categoryId = Long.valueOf(submittedValue); - - // Try to get user instance from it - category = CATEGORY_LIST_CONTROLLER.findCategoryById(categoryId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final CategoryNotFoundException ex) { - // Debug message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N - } - - // Return it - return category; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Category value) { - // Is the object null? - if ((null == value) || (String.valueOf(value).isEmpty())) { - // Is null - return ""; //NOI18N - } - - // Return id number - return String.valueOf(value.getCategoryId()); - } - -} diff --git a/web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl b/web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl index 1c4903cf..c016be80 100644 --- a/web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl +++ b/web/WEB-INF/templates/admin/generic_product/admin_form_generic_product_data.tpl @@ -119,7 +119,7 @@ value="#{basicDataListController.allBasicData}" var="basicData" itemValue="#{basicData}" - itemLabel="#{beanHelper.renderBasicData(basicData, true)}" + itemLabel="#{beanHelper.renderBasicData(basicData, true, false)}" /> diff --git a/web/admin/generic_product/admin_generic_product_list.xhtml b/web/admin/generic_product/admin_generic_product_list.xhtml index 79e12d4f..8343e6f8 100644 --- a/web/admin/generic_product/admin_generic_product_list.xhtml +++ b/web/admin/generic_product/admin_generic_product_list.xhtml @@ -217,14 +217,14 @@ value="#{basicDataListController.allBasicData}" var="basicData" itemValue="#{basicData}" - itemLabel="#{beanHelper.renderBasicData(basicData, true)}" + itemLabel="#{beanHelper.renderBasicData(basicData, true, false)}" />