From: Roland Häder Date: Sun, 3 Sep 2017 02:40:58 +0000 (+0200) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7883a0f8261aae62baa0f5bdddfdeff0c7548913;p=jfinancials-war.git 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 Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsBusinessDataWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsBusinessDataWebRequestBean.java index b9a26cb7..d2d58181 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsBusinessDataWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/basicdata/FinancialsBusinessDataWebRequestBean.java @@ -60,8 +60,8 @@ public class FinancialsBusinessDataWebRequestBean extends BaseFinancialsControll * 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/jfinancials/beans/business/employee/FinancialsCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/business/employee/FinancialsCompanyEmployeeWebRequestBean.java index f4ca6008..edf21434 100644 --- a/src/java/org/mxchange/jfinancials/beans/business/employee/FinancialsCompanyEmployeeWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/business/employee/FinancialsCompanyEmployeeWebRequestBean.java @@ -54,8 +54,8 @@ public class FinancialsCompanyEmployeeWebRequestBean extends BaseFinancialsContr * 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/jfinancials/beans/contact/FinancialsContactWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebRequestBean.java index 7443a08e..7a819789 100644 --- a/src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/contact/FinancialsContactWebRequestBean.java @@ -102,8 +102,8 @@ public class FinancialsContactWebRequestBean extends BaseFinancialsController im * 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 FinancialsContactWebRequestBean extends BaseFinancialsController im * 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/jfinancials/beans/contact/phone/FinancialsContactPhoneWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsContactPhoneWebRequestBean.java index c43241ab..912e88c1 100644 --- a/src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsContactPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/contact/phone/FinancialsContactPhoneWebRequestBean.java @@ -69,8 +69,8 @@ public class FinancialsContactPhoneWebRequestBean extends BaseFinancialsControll * 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/jfinancials/beans/country/FinancialsCountryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/country/FinancialsCountryWebRequestBean.java index 1b99bd27..ea8c5265 100644 --- a/src/java/org/mxchange/jfinancials/beans/country/FinancialsCountryWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/country/FinancialsCountryWebRequestBean.java @@ -57,8 +57,8 @@ public class FinancialsCountryWebRequestBean extends BaseFinancialsController im * 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/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java index a1d6a378..3586a4bc 100644 --- a/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java +++ b/src/java/org/mxchange/jfinancials/beans/helper/FinancialsWebRequestHelperBean.java @@ -29,6 +29,7 @@ import org.mxchange.jfinancials.beans.BaseFinancialsController; import org.mxchange.jfinancials.beans.contact.FinancialsAdminContactWebRequestController; import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController; import org.mxchange.jfinancials.beans.user.FinancialsAdminUserWebRequestController; +import org.mxchange.jfinancials.beans.user.FinancialsUserWebRequestController; import org.mxchange.jphone.events.fax.created.CreatedFaxNumberEvent; import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent; import org.mxchange.jphone.events.landline.created.CreatedLandLineNumberEvent; @@ -41,7 +42,6 @@ import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jusercore.events.user.created.CreatedUserEvent; import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; import org.mxchange.jusercore.model.user.User; -import org.mxchange.jfinancials.beans.user.FinancialsUserWebRequestController; /** * A general helper for beans diff --git a/src/java/org/mxchange/jfinancials/beans/mobileprovider/FinancialsMobileProviderWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/mobileprovider/FinancialsMobileProviderWebRequestBean.java index 51aac6d3..76ab69de 100644 --- a/src/java/org/mxchange/jfinancials/beans/mobileprovider/FinancialsMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/mobileprovider/FinancialsMobileProviderWebRequestBean.java @@ -57,8 +57,8 @@ public class FinancialsMobileProviderWebRequestBean extends BaseFinancialsContro * "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/jfinancials/beans/phone/FinancialsPhoneWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/phone/FinancialsPhoneWebRequestBean.java index 2ff45ecd..b773700e 100644 --- a/src/java/org/mxchange/jfinancials/beans/phone/FinancialsPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/phone/FinancialsPhoneWebRequestBean.java @@ -66,22 +66,22 @@ public class FinancialsPhoneWebRequestBean extends BaseFinancialsController impl * 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/jfinancials/beans/user/FinancialsUserWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebRequestBean.java index e6c1df1d..e0c3519a 100644 --- a/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/user/FinancialsUserWebRequestBean.java @@ -119,8 +119,8 @@ public class FinancialsUserWebRequestBean extends BaseFinancialsController imple * 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 FinancialsUserWebRequestBean extends BaseFinancialsController imple * 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/jfinancials/beans/user/activity/FinancialsUserActivityWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebRequestBean.java index d9565b89..dc0b7f23 100644 --- a/src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/user/activity/FinancialsUserActivityWebRequestBean.java @@ -79,8 +79,8 @@ public class FinancialsUserActivityWebRequestBean extends BaseFinancialsControll * "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/jfinancials/beans/user/email_address/FinancialsEmailChangeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebRequestBean.java index 0eb28e83..9ded8b58 100644 --- a/src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/user/email_address/FinancialsEmailChangeWebRequestBean.java @@ -79,8 +79,8 @@ public class FinancialsEmailChangeWebRequestBean extends BaseFinancialsControlle * 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/jfinancials/converter/business/basicdata/FinancialsBusinessContactConverter.java b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBusinessContactConverter.java index 6c2d275f..cec53b34 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBusinessContactConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/basicdata/FinancialsBusinessContactConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.jfinancials.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 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; import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundException; @@ -31,14 +35,13 @@ import org.mxchange.jcontactsbusiness.exceptions.basicdata.BusinessDataNotFoundE *

* @author Roland Häder */ -@FacesConverter (value = "BusinessContactConverter", managed = true) +@FacesConverter (value = "BusinessContactConverter") public class FinancialsBusinessContactConverter implements Converter { /** * Business contact EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote") - private BusinessDataSessionBeanRemote basicDataBean; + private static BusinessDataSessionBeanRemote BASIC_DATA_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class FinancialsBusinessContactConverter implements Converter * @author Roland Häder */ -@FacesConverter (value = "CompanyEmployeeConverter", managed = true) +@FacesConverter (value = "CompanyEmployeeConverter") public class FinancialsCompanyEmployeeConverter implements Converter { /** * CompanyEmployee EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote") - private CompanyEmployeeSessionBeanRemote companyEmployeeBean; + private static CompanyEmployeeSessionBeanRemote COMPANY_EMPLOYEE_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class FinancialsCompanyEmployeeConverter implements Converter { @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 @@ -65,7 +82,7 @@ public class FinancialsCompanyEmployeeConverter 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/jfinancials/converter/business/headquarters/FinancialsCompanyHeadquartersConverter.java b/src/java/org/mxchange/jfinancials/converter/business/headquarters/FinancialsCompanyHeadquartersConverter.java index ecc13107..a5e95756 100644 --- a/src/java/org/mxchange/jfinancials/converter/business/headquarters/FinancialsCompanyHeadquartersConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/business/headquarters/FinancialsCompanyHeadquartersConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.jfinancials.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.headquarters.CompanyHeadquartersSessionBeanRemote; import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData; @@ -31,14 +35,13 @@ import org.mxchange.jcontactsbusiness.headquarters.HeadquartersData; *

* @author Roland Häder */ -@FacesConverter (value = "CompanyHeadquartersConverter", managed = true) +@FacesConverter (value = "CompanyHeadquartersConverter") public class FinancialsCompanyHeadquartersConverter implements Converter { /** * CompanyEmployee EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/companyEmployee!org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersSessionBeanRemote") - private CompanyHeadquartersSessionBeanRemote companyHeadquartersBean; + private static CompanyHeadquartersSessionBeanRemote COMPANY_HEADQUARTERS_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class FinancialsCompanyHeadquartersConverter implements Converter * @author Roland Häder */ -@FacesConverter (value = "ContactConverter", managed = true) +@FacesConverter (value = "ContactConverter") public class FinancialsContactConverter implements Converter { /** * Contact 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 FinancialsContactConverter 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 FinancialsContactConverter 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/jfinancials/converter/country/FinancialsCountryConverter.java b/src/java/org/mxchange/jfinancials/converter/country/FinancialsCountryConverter.java index b7689982..953527bf 100644 --- a/src/java/org/mxchange/jfinancials/converter/country/FinancialsCountryConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/country/FinancialsCountryConverter.java @@ -18,12 +18,16 @@ package org.mxchange.jfinancials.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.data.Country; import org.mxchange.jcountry.data.CountrySingletonBeanRemote; @@ -32,14 +36,13 @@ import org.mxchange.jcountry.data.CountrySingletonBeanRemote; *

* @author Roland Häder */ -@FacesConverter (value = "CountryConverter", managed = true) +@FacesConverter (value = "CountryConverter") public class FinancialsCountryConverter implements Converter { /** * Country bean */ - @EJB (lookup = "java:global/jfinancials-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote") - private CountrySingletonBeanRemote countryBean; + private static CountrySingletonBeanRemote COUNTRY_BEAN; /** * Default constructor @@ -49,6 +52,20 @@ public class FinancialsCountryConverter implements Converter { @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 +76,7 @@ public class FinancialsCountryConverter 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/jfinancials/converter/fax/FinancialsFaxNumberConverter.java b/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java index 41a269bf..64da2231 100644 --- a/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java +++ b/src/java/org/mxchange/jfinancials/converter/fax/FinancialsFaxNumberConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.jfinancials.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.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; @@ -31,14 +35,13 @@ import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; *

* @author Roland Häder */ -@FacesConverter (value = "FaxNumberConverter", managed = true) +@FacesConverter (value = "FaxNumberConverter") public class FinancialsFaxNumberConverter implements Converter { /** * Phone EJB */ - @EJB(lookup = "java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote") - private PhoneSessionBeanRemote phoneBean; + private static PhoneSessionBeanRemote PHONE_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class FinancialsFaxNumberConverter implements Converter * @author Roland Häder */ -@FacesConverter (value = "LandLineNumberConverter", managed = true) +@FacesConverter (value = "LandLineNumberConverter") public class FinancialsLandLineNumberConverter implements Converter { /** * Phone EJB */ - @EJB(lookup = "java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote") - private PhoneSessionBeanRemote phoneBean; + private static PhoneSessionBeanRemote PHONE_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class FinancialsLandLineNumberConverter implements Converter * @author Roland Häder */ -@FacesConverter (value = "MobileNumberConverter", managed = true) +@FacesConverter (value = "MobileNumberConverter") public class FinancialsMobileNumberConverter implements Converter { /** * Phone EJB */ - @EJB (lookup = "java:global/jfinancials-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote") - private PhoneSessionBeanRemote phoneBean; + private static PhoneSessionBeanRemote PHONE_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class FinancialsMobileNumberConverter implements Converter * @author Roland Häder */ -@FacesConverter (value = "UserConverter", managed = true) +@FacesConverter (value = "UserConverter") public class FinancialsUserConverter implements Converter { /** * User EJB */ - @EJB(lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") - private UserSessionBeanRemote userBean; + private static UserSessionBeanRemote USER_BEAN; /** * Default constructor @@ -48,6 +50,20 @@ public class FinancialsUserConverter implements Converter { @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 +81,7 @@ public class FinancialsUserConverter 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/jfinancials/validator/business/basicdata/FinancialsCompanyNameValidator.java b/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsCompanyNameValidator.java index 258303e2..968ec1a9 100644 --- a/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsCompanyNameValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/business/basicdata/FinancialsCompanyNameValidator.java @@ -17,12 +17,14 @@ package org.mxchange.jfinancials.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; @@ -31,22 +33,35 @@ import org.mxchange.jcoreee.validator.string.BaseStringValidator; *

* @author Roland Häder */ -@FacesValidator (value = "CompanyNameValidator", managed = true) +@FacesValidator (value = "CompanyNameValidator") public class FinancialsCompanyNameValidator 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 @@ -75,7 +90,7 @@ public class FinancialsCompanyNameValidator 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/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java b/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java index a185a4fd..e9a0a2ae 100644 --- a/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java @@ -18,12 +18,14 @@ package org.mxchange.jfinancials.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.contact.ContactSessionBeanRemote; import org.mxchange.jcoreee.validator.string.BaseStringValidator; @@ -32,14 +34,13 @@ import org.mxchange.jcoreee.validator.string.BaseStringValidator; *

* @author Roland Häder */ -@FacesValidator (value = "EmailAddressValidator", managed = true) +@FacesValidator (value = "EmailAddressValidator") public class FinancialsEmailAddressValidator 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 @@ -64,6 +65,20 @@ public class FinancialsEmailAddressValidator extends BaseStringValidator { @Override public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { + // 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); + } + } + System.out.println(this.getClass().getSimpleName() + ".validate(): component.clientId=" + component.getClientId()); // The required field String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N @@ -121,7 +136,7 @@ public class FinancialsEmailAddressValidator 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/jfinancials/validator/user/FinancialsUserIdValidator.java b/src/java/org/mxchange/jfinancials/validator/user/FinancialsUserIdValidator.java index ff6ec55a..da0ccdab 100644 --- a/src/java/org/mxchange/jfinancials/validator/user/FinancialsUserIdValidator.java +++ b/src/java/org/mxchange/jfinancials/validator/user/FinancialsUserIdValidator.java @@ -17,12 +17,14 @@ package org.mxchange.jfinancials.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; @@ -31,19 +33,18 @@ import org.mxchange.jusercore.model.user.UserSessionBeanRemote; *

* @author Roland Häder */ -@FacesValidator (value = "UserIdValidator", managed = true) +@FacesValidator (value = "UserIdValidator") public class FinancialsUserIdValidator 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 FinancialsUserIdValidator 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 FinancialsUserIdValidator 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) {