From 1e23a663deba8ce12e98b0f4707e20513fa1e8e4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 3 Sep 2017 04:40:58 +0200 Subject: [PATCH] Please cherry-pick: - if you get something about non-serializable injection, strange things happen, sometimes it works here, sometimes not ... :-( - had to go back to programatic JNDI lookup in converters/validators as the JSF 2.3 version + xsd reference did mess around with faces-config.xml auto-complete (NetBeans) and it looks like that context parameters are not loaded - this way, some lookup() calls are not saved (unmanaged by container) but at least it works MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../PizzaBusinessDataWebRequestBean.java | 4 +-- .../PizzaCompanyEmployeeWebRequestBean.java | 4 +-- .../contact/PizzaContactWebRequestBean.java | 8 ++--- .../PizzaContactPhoneWebRequestBean.java | 4 +-- .../country/PizzaCountryWebRequestBean.java | 4 +-- .../PizzaMobileProviderWebRequestBean.java | 4 +-- .../beans/phone/PizzaPhoneWebRequestBean.java | 12 +++---- .../beans/user/PizzaUserWebRequestBean.java | 8 ++--- .../PizzaUserActivityWebRequestBean.java | 4 +-- .../PizzaEmailChangeWebRequestBean.java | 4 +-- .../PizzaBusinessContactConverter.java | 34 +++++++++++++------ .../PizzaCompanyEmployeeConverter.java | 33 ++++++++++++------ .../PizzaCompanyHeadquartersConverter.java | 31 +++++++++++------ .../contact/PizzaContactConverter.java | 25 +++++++++++--- .../country/PizzaCountryConverter.java | 31 +++++++++++------ .../fax/PizzaFaxNumberConverter.java | 31 +++++++++++------ .../PizzaLandLineNumberConverter.java | 31 +++++++++++------ .../mobile/PizzaMobileNumberConverter.java | 25 +++++++++++--- .../converter/user/PizzaUserConverter.java | 30 ++++++++++------ .../basicdata/PizzaCompanyNameValidator.java | 32 ++++++++++++----- .../PizzaEmailAddressValidator.java | 32 ++++++++++------- .../validator/user/PizzaUserIdValidator.java | 29 ++++++++++++---- 22 files changed, 285 insertions(+), 135 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/beans/business/basicdata/PizzaBusinessDataWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/business/basicdata/PizzaBusinessDataWebRequestBean.java index bdd880e7..6e0f01c1 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/business/basicdata/PizzaBusinessDataWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/business/basicdata/PizzaBusinessDataWebRequestBean.java @@ -58,8 +58,8 @@ public class PizzaBusinessDataWebRequestBean extends BasePizzaController impleme * A list of all registered companies (globally) */ @Inject - @NamedCache (cacheName = "basicDataCache", managementEnabled = true) - private transient Cache basicDataCache; + @NamedCache (cacheName = "basicDataCache") + private Cache basicDataCache; /** * EJB for general basic business data purposes diff --git a/src/java/org/mxchange/pizzaapplication/beans/business/employee/PizzaCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/business/employee/PizzaCompanyEmployeeWebRequestBean.java index f7ec105a..f129bbdd 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/business/employee/PizzaCompanyEmployeeWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/business/employee/PizzaCompanyEmployeeWebRequestBean.java @@ -54,8 +54,8 @@ public class PizzaCompanyEmployeeWebRequestBean extends BasePizzaController impl * List of all company employees */ @Inject - @NamedCache (cacheName = "companyEmployeeCache", managementEnabled = true) - private transient Cache companyEmployeeCache; + @NamedCache (cacheName = "companyEmployeeCache") + private Cache companyEmployeeCache; /** * Default constructor diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebRequestBean.java index 7d374b89..beb6b4a5 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/PizzaContactWebRequestBean.java @@ -102,8 +102,8 @@ public class PizzaContactWebRequestBean extends BasePizzaController implements P * Contact list */ @Inject - @NamedCache (cacheName = "contactsCache", managementEnabled = true) - private transient Cache contactsCache; + @NamedCache (cacheName = "contactsCache") + private Cache contactsCache; /** * Country instance @@ -119,8 +119,8 @@ public class PizzaContactWebRequestBean extends BasePizzaController implements P * Email address list */ @Inject - @NamedCache (cacheName = "emailAddressCache", managementEnabled = true) - private transient Cache emailAddressCache; + @NamedCache (cacheName = "emailAddressCache") + private Cache emailAddressCache; /** * Email address repeated diff --git a/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebRequestBean.java index 7c1ffd64..f8179638 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/contact/phone/PizzaContactPhoneWebRequestBean.java @@ -69,8 +69,8 @@ public class PizzaContactPhoneWebRequestBean extends BasePizzaController impleme * relationship (one contact, many numbers). */ @Inject - @NamedCache (cacheName = "contactsPhoneCache", managementEnabled = true) - private transient Cache> contactsPhoneCache; + @NamedCache (cacheName = "contactsPhoneCache") + private Cache> contactsPhoneCache; /** * fax number diff --git a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebRequestBean.java index eaa490f3..16a09c03 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/country/PizzaCountryWebRequestBean.java @@ -57,8 +57,8 @@ public class PizzaCountryWebRequestBean extends BasePizzaController implements P * List of all countries */ @Inject - @NamedCache (cacheName = "countryCache", managementEnabled = true) - private transient Cache countryCache; + @NamedCache (cacheName = "countryCache") + private Cache countryCache; /** * Default constructor diff --git a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java index 4eacb4e0..1929e20f 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/mobileprovider/PizzaMobileProviderWebRequestBean.java @@ -57,8 +57,8 @@ public class PizzaMobileProviderWebRequestBean extends BasePizzaController imple * "Cached" list of mobile providers */ @Inject - @NamedCache (cacheName = "mobileProviderCache", managementEnabled = true) - private transient Cache mobileProviderCache; + @NamedCache (cacheName = "mobileProviderCache") + private Cache mobileProviderCache; /** * Default constructor diff --git a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebRequestBean.java index dca8cd8c..4cbf5f83 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/phone/PizzaPhoneWebRequestBean.java @@ -66,22 +66,22 @@ public class PizzaPhoneWebRequestBean extends BasePizzaController implements Piz * All fax numbers */ @Inject - @NamedCache (cacheName = "faxNumberCache", managementEnabled = true) - private transient Cache faxNumberCache; + @NamedCache (cacheName = "faxNumberCache") + private Cache faxNumberCache; /** * All land-line numbers */ @Inject - @NamedCache (cacheName = "landLineNumberCache", managementEnabled = true) - private transient Cache landLineNumberCache; + @NamedCache (cacheName = "landLineNumberCache") + private Cache landLineNumberCache; /** * All mobile numbers */ @Inject - @NamedCache (cacheName = "mobileNumberCache", managementEnabled = true) - private transient Cache mobileNumberCache; + @NamedCache (cacheName = "mobileNumberCache") + private Cache mobileNumberCache; /** * General EJB for phone numbers diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebRequestBean.java index a86c7186..af507220 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/PizzaUserWebRequestBean.java @@ -119,8 +119,8 @@ public class PizzaUserWebRequestBean extends BasePizzaController implements Pizz * A list of all user profiles */ @Inject - @NamedCache (cacheName = "userCache", managementEnabled = true) - private transient Cache userCache; + @NamedCache (cacheName = "userCache") + private Cache userCache; /** * User id @@ -142,8 +142,8 @@ public class PizzaUserWebRequestBean extends BasePizzaController implements Pizz * User name list */ @Inject - @NamedCache (cacheName = "userNameCache", managementEnabled = true) - private transient Cache userNameCache; + @NamedCache (cacheName = "userNameCache") + private Cache userNameCache; /** * User password (clear-text from web form) diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebRequestBean.java index c9857a12..48fa139f 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/activity/PizzaUserActivityWebRequestBean.java @@ -79,8 +79,8 @@ public class PizzaUserActivityWebRequestBean extends BasePizzaController impleme * "Cache" for activity log per user */ @Inject - @NamedCache (cacheName = "userActivityCache", managementEnabled = true) - private transient Cache> userActivityCache; + @NamedCache (cacheName = "userActivityCache") + private Cache> userActivityCache; /** * Default constructor diff --git a/src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebRequestBean.java b/src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebRequestBean.java index 9391927a..239ea9a6 100644 --- a/src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebRequestBean.java +++ b/src/java/org/mxchange/pizzaapplication/beans/user/email_address/PizzaEmailChangeWebRequestBean.java @@ -79,8 +79,8 @@ public class PizzaEmailChangeWebRequestBean extends BasePizzaController implemen * Local list of already queued email addresses */ @Inject - @NamedCache (cacheName = "queuedEmailCache", managementEnabled = true) - private transient Cache queuedEmailCache; + @NamedCache (cacheName = "queuedEmailCache") + private Cache queuedEmailCache; /** * Login controller (bean) diff --git a/src/java/org/mxchange/pizzaapplication/converter/business/basicdata/PizzaBusinessContactConverter.java b/src/java/org/mxchange/pizzaapplication/converter/business/basicdata/PizzaBusinessContactConverter.java index a1a771f2..b2d7f090 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/business/basicdata/PizzaBusinessContactConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/business/basicdata/PizzaBusinessContactConverter.java @@ -16,13 +16,18 @@ */ package org.mxchange.pizzaapplication.converter.business.basicdata; -import javax.ejb.EJB; +import javax.faces.application.FacesMessage; 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.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataNotFoundException; +import javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcontactsbusiness.basicdata.BusinessBasicData; +import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote; /** * Converter for contact id <-> valid business contact instance @@ -35,17 +40,24 @@ public class PizzaBusinessContactConverter implements Converter { /** * CompanyEmployee EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote") - private CompanyEmployeeSessionBeanRemote companyEmployeeBean; - - /** - * Default constructor - */ - public PizzaCompanyEmployeeConverter () { - } + private static CompanyEmployeeSessionBeanRemote COMPANY_EMPLOYEE_BEAN; @Override public Employee getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (COMPANY_EMPLOYEE_BEAN == null) { + try { + // Not yet, attempt lookup + Context initial = new InitialContext(); + + // Lookup EJB + COMPANY_EMPLOYEE_BEAN = (CompanyEmployeeSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote"); + } catch (final NamingException ex) { + // Throw it again + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); + } + } + // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -63,7 +76,7 @@ public class PizzaCompanyEmployeeConverter implements Converter { Long employeeId = Long.valueOf(submittedValue); // Try to get user instance from it - companyEmployee = this.companyEmployeeBean.findCompanyEmployeeById(employeeId); + companyEmployee = COMPANY_EMPLOYEE_BEAN.findCompanyEmployeeById(employeeId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); diff --git a/src/java/org/mxchange/pizzaapplication/converter/business/headquarters/PizzaCompanyHeadquartersConverter.java b/src/java/org/mxchange/pizzaapplication/converter/business/headquarters/PizzaCompanyHeadquartersConverter.java index 1233fa4a..59dc0148 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/business/headquarters/PizzaCompanyHeadquartersConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/business/headquarters/PizzaCompanyHeadquartersConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.pizzaapplication.converter.business.headquarters; -import javax.ejb.EJB; +import javax.faces.application.FacesMessage; 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 javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jcontactsbusiness.exceptions.headquarters.CompanyHeadquartersNotFoundException; import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersSessionBeanRemote; import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; @@ -37,17 +41,24 @@ public class PizzaCompanyHeadquartersConverter implements Converter { /** * User EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") - private ContactSessionBeanRemote contactBean; + private static ContactSessionBeanRemote CONTACT_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class PizzaContactConverter implements Converter { @Override public Contact getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (CONTACT_BEAN == null) { + try { + // Not yet, attempt lookup + Context initial = new InitialContext(); + + // Lookup EJB + CONTACT_BEAN = (ContactSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); + } catch (final NamingException ex) { + // Throw it again + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); + } + } + // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -65,7 +82,7 @@ public class PizzaContactConverter implements Converter { Long contactId = Long.valueOf(submittedValue); // Try to get user instance from it - contact = this.contactBean.findContactById(contactId); + contact = this.CONTACT_BEAN.findContactById(contactId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); diff --git a/src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java b/src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java index e63d29f2..542b631e 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/country/PizzaCountryConverter.java @@ -18,12 +18,16 @@ package org.mxchange.pizzaapplication.converter.country; import java.util.List; import java.util.Objects; -import javax.ejb.EJB; +import javax.faces.application.FacesMessage; 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 javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote; @@ -38,17 +42,24 @@ public class PizzaCountryConverter implements Converter { /** * Country bean */ - @EJB (lookup = "java:global/jfinancials-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote") - private CountrySingletonBeanRemote countryBean; - - /** - * Default constructor - */ - public PizzaCountryConverter () { - } + private static CountrySingletonBeanRemote COUNTRY_BEAN; @Override public Country getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (COUNTRY_BEAN == null) { + try { + // Not yet, attempt lookup + Context initial = new InitialContext(); + + // Lookup EJB + COUNTRY_BEAN = (CountrySingletonBeanRemote) initial.lookup("java:global/jfinancials-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote"); + } catch (final NamingException ex) { + // Throw it again + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); + } + } + // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -59,7 +70,7 @@ public class PizzaCountryConverter implements Converter { } // Get full list - List countryList = this.countryBean.allCountries(); + List countryList = COUNTRY_BEAN.allCountries(); // Init value Country country = null; diff --git a/src/java/org/mxchange/pizzaapplication/converter/fax/PizzaFaxNumberConverter.java b/src/java/org/mxchange/pizzaapplication/converter/fax/PizzaFaxNumberConverter.java index 7e947b23..1e031fca 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/fax/PizzaFaxNumberConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/fax/PizzaFaxNumberConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.pizzaapplication.converter.fax; -import javax.ejb.EJB; +import javax.faces.application.FacesMessage; 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 javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote; @@ -37,17 +41,24 @@ public class PizzaFaxNumberConverter implements Converter { /** * Phone EJB */ - @EJB(lookup = "java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote") - private PhoneSessionBeanRemote phoneBean; - - /** - * Default constructor - */ - public PizzaFaxNumberConverter () { - } + private static PhoneSessionBeanRemote PHONE_BEAN; @Override public DialableFaxNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (PHONE_BEAN == null) { + try { + // Not yet, attempt lookup + Context initial = new InitialContext(); + + // Lookup EJB + PHONE_BEAN = (PhoneSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); + } catch (final NamingException ex) { + // Throw it again + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); + } + } + // Log message // @TODO Not possible here: this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: context={1},component={2},submittedValue={3} - CALLED!", this.getClass().getSimpleName(), context, component, submittedValue)); //NOI18N @@ -70,7 +81,7 @@ public class PizzaFaxNumberConverter implements Converter { // Log message // @TODO Not possible here: this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject: faxNumberId={1}", this.getClass().getSimpleName(), faxNumberId)); //NOI18N // Try to get mobile instance from it - faxNumber = this.phoneBean.findFaxNumberById(faxNumberId); + faxNumber = PHONE_BEAN.findFaxNumberById(faxNumberId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); diff --git a/src/java/org/mxchange/pizzaapplication/converter/landline/PizzaLandLineNumberConverter.java b/src/java/org/mxchange/pizzaapplication/converter/landline/PizzaLandLineNumberConverter.java index fb775054..0fc2270c 100644 --- a/src/java/org/mxchange/pizzaapplication/converter/landline/PizzaLandLineNumberConverter.java +++ b/src/java/org/mxchange/pizzaapplication/converter/landline/PizzaLandLineNumberConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.pizzaapplication.converter.landline; -import javax.ejb.EJB; +import javax.faces.application.FacesMessage; 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 javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote; @@ -37,17 +41,24 @@ public class PizzaLandLineNumberConverter implements Converter { /** * User EJB */ - @EJB(lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") - private UserSessionBeanRemote userBean; - - /** - * Default constructor - */ - public PizzaUserConverter () { - } + private static UserSessionBeanRemote USER_BEAN; @Override public User getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (USER_BEAN == null) { + try { + // Not yet, attempt lookup + Context initial = new InitialContext(); + + // Lookup EJB + USER_BEAN = (UserSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); + } catch (final NamingException ex) { + // Throw it again + throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); + } + } + // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -65,7 +75,7 @@ public class PizzaUserConverter implements Converter { Long userId = Long.valueOf(submittedValue); // Try to get user instance from it - user = this.userBean.findUserById(userId); + user = USER_BEAN.findUserById(userId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); diff --git a/src/java/org/mxchange/pizzaapplication/validator/business/basicdata/PizzaCompanyNameValidator.java b/src/java/org/mxchange/pizzaapplication/validator/business/basicdata/PizzaCompanyNameValidator.java index 155d0d60..3c9f5572 100644 --- a/src/java/org/mxchange/pizzaapplication/validator/business/basicdata/PizzaCompanyNameValidator.java +++ b/src/java/org/mxchange/pizzaapplication/validator/business/basicdata/PizzaCompanyNameValidator.java @@ -17,12 +17,15 @@ package org.mxchange.pizzaapplication.validator.business.basicdata; import java.text.MessageFormat; -import javax.ejb.EJB; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote; import org.mxchange.jcoreee.validator.string.BaseStringValidator; /** @@ -30,22 +33,35 @@ import org.mxchange.jcoreee.validator.string.BaseStringValidator; *

* @author Roland Häder */ -@FacesValidator (value = "CompanyNameValidator", managed = true) +@FacesValidator ("CompanyNameValidator") public class PizzaCompanyNameValidator extends BaseStringValidator { /** - * Serial number + * Business contact EJB */ - private static final long serialVersionUID = 57_283_657_476_561L; + private static BusinessDataSessionBeanRemote BASIC_DATA_BEAN; /** - * Business contact EJB + * Serial number */ - @EJB (lookup = "java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote") - private BusinessDataSessionBeanRemote basicDataBean; + private static final long serialVersionUID = 57_283_657_476_561L; @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // Is the instance there? + if (BASIC_DATA_BEAN == null) { + try { + // Not yet, attempt lookup + Context initial = new InitialContext(); + + // Lookup EJB + BASIC_DATA_BEAN = (BusinessDataSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote"); + } catch (final NamingException ex) { + // Throw it again + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); + } + } + // All accepted, required fields String[] requiredFields = {"companyName"}; //NOI18N @@ -74,7 +90,7 @@ public class PizzaCompanyNameValidator extends BaseStringValidator { } // Check if name is already used - Boolean nameExists = this.basicDataBean.isCompanyNameUsed(companyName); + Boolean nameExists = BASIC_DATA_BEAN.isCompanyNameUsed(companyName); // Is the user id valid? if ((!nameExists) && (checkExisting)) { diff --git a/src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java b/src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java index 9f29d9c8..2035efee 100644 --- a/src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java +++ b/src/java/org/mxchange/pizzaapplication/validator/emailaddress/PizzaEmailAddressValidator.java @@ -18,12 +18,14 @@ package org.mxchange.pizzaapplication.validator.emailaddress; import java.text.MessageFormat; import java.util.regex.Pattern; -import javax.ejb.EJB; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote; import org.mxchange.jcoreee.validator.string.BaseStringValidator; @@ -38,8 +40,7 @@ public class PizzaEmailAddressValidator extends BaseStringValidator { /** * Contact session-scoped bean */ - @EJB (lookup = "java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") - private ContactSessionBeanRemote contactBean; + private static ContactSessionBeanRemote CONTACT_BEAN; /** * Email pattern @@ -56,15 +57,22 @@ public class PizzaEmailAddressValidator extends BaseStringValidator { */ private static final long serialVersionUID = 187_536_745_607_192L; - /** - * Default constructor - */ - public PizzaEmailAddressValidator () { - } - @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { - System.out.println(this.getClass().getSimpleName() + ".validate(): component.clientId=" + component.getClientId()); + // Is the instance there? + if (CONTACT_BEAN == null) { + try { + // Not yet, attempt lookup + Context initial = new InitialContext(); + + // Lookup EJB + CONTACT_BEAN = (ContactSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); + } catch (final NamingException ex) { + // Throw it again + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); + } + } + // The required field String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N @@ -75,7 +83,6 @@ public class PizzaEmailAddressValidator extends BaseStringValidator { if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N // Get attribute Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N - System.out.println(this.getClass().getSimpleName() + ".validate():attribute=" + attribute); // Make sure, it is Boolean as no String is accepted anymore if (!(attribute instanceof String)) { @@ -86,7 +93,6 @@ public class PizzaEmailAddressValidator extends BaseStringValidator { // Securely cast it allowEmptyValue = Boolean.parseBoolean((String) attribute); } - System.out.println(this.getClass().getSimpleName() + ".validate(): allowEmptyValue=" + allowEmptyValue); // Pre-validation (example: not null, not a string, empty string ...) super.preValidate(context, component, value, requiredFields, allowEmptyValue); @@ -121,7 +127,7 @@ public class PizzaEmailAddressValidator extends BaseStringValidator { String clientId = component.getClientId(); // Is it registered? - Boolean isRegistered = this.contactBean.isEmailAddressRegistered(emailAddress); + Boolean isRegistered = CONTACT_BEAN.isEmailAddressRegistered(emailAddress); // Is the email address already registered? if ((!clientId.endsWith("resendEmailAddress")) && (isRegistered)) { //NOI18N diff --git a/src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java b/src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java index 57a8f6ec..abde9cee 100644 --- a/src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java +++ b/src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java @@ -17,12 +17,14 @@ package org.mxchange.pizzaapplication.validator.user; import java.text.MessageFormat; -import javax.ejb.EJB; import javax.faces.application.FacesMessage; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.validator.FacesValidator; import javax.faces.validator.ValidatorException; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; import org.mxchange.jcoreee.validator.number.BaseNumberValidator; import org.mxchange.jusercore.model.user.UserSessionBeanRemote; @@ -35,15 +37,14 @@ import org.mxchange.jusercore.model.user.UserSessionBeanRemote; public class PizzaUserIdValidator extends BaseNumberValidator { /** - * Serial number + * Remote bean */ - private static final long serialVersionUID = 12_869_569_314_764_690L; + private static UserSessionBeanRemote USER_BEAN; /** - * Remote bean + * Serial number */ - @EJB (lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") - private UserSessionBeanRemote userBean; + private static final long serialVersionUID = 12_869_569_314_764_690L; /** * Default constructor @@ -53,6 +54,20 @@ public class PizzaUserIdValidator extends BaseNumberValidator { @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // Is the instance there? + if (USER_BEAN == null) { + try { + // Not yet, attempt lookup + Context initial = new InitialContext(); + + // Lookup EJB + USER_BEAN = (UserSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); + } catch (final NamingException ex) { + // Throw it again + throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); + } + } + // All accepted, required fields String[] requiredFields = {"userId"}; //NOI18N @@ -63,7 +78,7 @@ public class PizzaUserIdValidator extends BaseNumberValidator { Long userId = (Long) value; // Define variable - Boolean ifUserExists = this.userBean.ifUserIdExists(userId); + Boolean ifUserExists = USER_BEAN.ifUserIdExists(userId); // Is the user id valid? if (!ifUserExists) { -- 2.39.5