From 9c86bfe3e6cc7038fbd4e8985c85bc607753ea5b 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 --- .../JobsBusinessDataWebRequestBean.java | 4 +-- .../JobsCompanyEmployeeWebRequestBean.java | 4 +-- .../contact/JobsContactWebRequestBean.java | 8 ++--- .../phone/JobsContactPhoneWebRequestBean.java | 4 +-- .../country/JobsCountryWebRequestBean.java | 4 +-- .../JobsMobileProviderWebRequestBean.java | 4 +-- .../beans/phone/JobsPhoneWebRequestBean.java | 12 ++++---- .../beans/user/JobsUserWebRequestBean.java | 8 ++--- .../JobsUserActivityWebRequestBean.java | 4 +-- .../JobsEmailChangeWebRequestBean.java | 4 +-- .../JobsBusinessContactConverter.java | 25 +++++++++++++--- .../JobsCompanyEmployeeConverter.java | 25 +++++++++++++--- .../JobsCompanyHeadquartersConverter.java | 25 +++++++++++++--- .../contact/JobsContactConverter.java | 25 +++++++++++++--- .../country/JobsCountryConverter.java | 25 +++++++++++++--- .../converter/fax/JobsFaxNumberConverter.java | 25 +++++++++++++--- .../landline/JobsLandLineNumberConverter.java | 25 +++++++++++++--- .../mobile/JobsMobileNumberConverter.java | 25 +++++++++++++--- .../converter/user/JobsUserConverter.java | 24 ++++++++++++--- .../basicdata/JobsCompanyNameValidator.java | 29 ++++++++++++++----- .../JobsEmailAddressValidator.java | 23 ++++++++++++--- .../validator/user/JobsUserIdValidator.java | 29 ++++++++++++++----- 22 files changed, 279 insertions(+), 82 deletions(-) diff --git a/src/java/org/mxchange/jjobs/beans/business/basicdata/JobsBusinessDataWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/basicdata/JobsBusinessDataWebRequestBean.java index 62f5ba12..943f1255 100644 --- a/src/java/org/mxchange/jjobs/beans/business/basicdata/JobsBusinessDataWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/basicdata/JobsBusinessDataWebRequestBean.java @@ -58,8 +58,8 @@ public class JobsBusinessDataWebRequestBean extends BaseJobsController implement * 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/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java index 6fe69dd6..76148389 100644 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java @@ -54,8 +54,8 @@ public class JobsCompanyEmployeeWebRequestBean extends BaseJobsController implem * 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/jjobs/beans/contact/JobsContactWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebRequestBean.java index 8079c240..2ff1ceb8 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/JobsContactWebRequestBean.java @@ -101,8 +101,8 @@ public class JobsContactWebRequestBean extends BaseJobsController implements Job * Contact list */ @Inject - @NamedCache (cacheName = "contactsCache", managementEnabled = true) - private transient Cache contactsCache; + @NamedCache (cacheName = "contactsCache") + private Cache contactsCache; /** * Country instance @@ -118,8 +118,8 @@ public class JobsContactWebRequestBean extends BaseJobsController implements Job * 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/jjobs/beans/contact/phone/JobsContactPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestBean.java index ae18da6e..ec93e9aa 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/JobsContactPhoneWebRequestBean.java @@ -68,8 +68,8 @@ public class JobsContactPhoneWebRequestBean extends BaseJobsController implement * 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/jjobs/beans/country/JobsCountryWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/country/JobsCountryWebRequestBean.java index 6394bb23..a580d442 100644 --- a/src/java/org/mxchange/jjobs/beans/country/JobsCountryWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/country/JobsCountryWebRequestBean.java @@ -56,8 +56,8 @@ public class JobsCountryWebRequestBean extends BaseJobsController implements Job * 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/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java index e53fb33c..d80dfaa6 100644 --- a/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsMobileProviderWebRequestBean.java @@ -57,8 +57,8 @@ public class JobsMobileProviderWebRequestBean extends BaseJobsController impleme * "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/jjobs/beans/phone/JobsPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/phone/JobsPhoneWebRequestBean.java index 94748e70..00fa4fd6 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsPhoneWebRequestBean.java @@ -65,22 +65,22 @@ public class JobsPhoneWebRequestBean extends BaseJobsController implements JobsP * 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/jjobs/beans/user/JobsUserWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebRequestBean.java index a42107a5..85584ba1 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsUserWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsUserWebRequestBean.java @@ -118,8 +118,8 @@ public class JobsUserWebRequestBean extends BaseJobsController implements JobsUs * A list of all user profiles */ @Inject - @NamedCache (cacheName = "userCache", managementEnabled = true) - private transient Cache userCache; + @NamedCache (cacheName = "userCache") + private Cache userCache; /** * User id @@ -141,8 +141,8 @@ public class JobsUserWebRequestBean extends BaseJobsController implements JobsUs * 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/jjobs/beans/user/activity/JobsUserActivityWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebRequestBean.java index e483a6fd..d18caa8d 100644 --- a/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/activity/JobsUserActivityWebRequestBean.java @@ -78,8 +78,8 @@ public class JobsUserActivityWebRequestBean extends BaseJobsController implement * "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/jjobs/beans/user/email_address/JobsEmailChangeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/email_address/JobsEmailChangeWebRequestBean.java index e853cad0..50a7c887 100644 --- a/src/java/org/mxchange/jjobs/beans/user/email_address/JobsEmailChangeWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/email_address/JobsEmailChangeWebRequestBean.java @@ -78,8 +78,8 @@ public class JobsEmailChangeWebRequestBean extends BaseJobsController implements * 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/jjobs/converter/business/basicdata/JobsBusinessContactConverter.java b/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBusinessContactConverter.java index d63a0c19..441c73ce 100644 --- a/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBusinessContactConverter.java +++ b/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBusinessContactConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.jjobs.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; @@ -37,8 +41,7 @@ public class JobsBusinessContactConverter implements Converter { /** * CompanyEmployee EJB */ - @EJB (lookup = "java:global/jjobs-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote") - private CompanyEmployeeSessionBeanRemote companyEmployeeBean; + private static CompanyEmployeeSessionBeanRemote COMPANY_EMPLOYEE_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class JobsCompanyEmployeeConverter 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/jjobs-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 JobsCompanyEmployeeConverter 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/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java b/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java index d06f9c9b..4f3b82e9 100644 --- a/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java +++ b/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.jjobs.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; @@ -37,8 +41,7 @@ public class JobsCompanyHeadquartersConverter implements Converter { /** * User EJB */ - @EJB (lookup = "java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") - private ContactSessionBeanRemote contactBean; + private static ContactSessionBeanRemote CONTACT_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class JobsContactConverter 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/jjobs-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 JobsContactConverter 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/jjobs/converter/country/JobsCountryConverter.java b/src/java/org/mxchange/jjobs/converter/country/JobsCountryConverter.java index 7f4df116..69e3a8c4 100644 --- a/src/java/org/mxchange/jjobs/converter/country/JobsCountryConverter.java +++ b/src/java/org/mxchange/jjobs/converter/country/JobsCountryConverter.java @@ -18,12 +18,16 @@ package org.mxchange.jjobs.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; @@ -38,8 +42,7 @@ public class JobsCountryConverter implements Converter { /** * Country bean */ - @EJB (lookup = "java:global/jjobs-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote") - private CountrySingletonBeanRemote countryBean; + private static CountrySingletonBeanRemote COUNTRY_BEAN; /** * Default constructor @@ -49,6 +52,20 @@ public class JobsCountryConverter 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/jjobs-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 JobsCountryConverter 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/jjobs/converter/fax/JobsFaxNumberConverter.java b/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java index f9cf8cfd..a469d940 100644 --- a/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.jjobs.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; @@ -37,8 +41,7 @@ public class JobsFaxNumberConverter implements Converter { /** * Phone EJB */ - @EJB(lookup = "java:global/jjobs-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote") - private PhoneSessionBeanRemote phoneBean; + private static PhoneSessionBeanRemote PHONE_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class JobsFaxNumberConverter implements Converter { @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/jjobs-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 +87,7 @@ public class JobsFaxNumberConverter 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/jjobs/converter/landline/JobsLandLineNumberConverter.java b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java index 8ec5d093..398c117e 100644 --- a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.jjobs.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.phonenumbers.landline.DialableLandLineNumber; import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; @@ -37,8 +41,7 @@ public class JobsLandLineNumberConverter implements Converter { /** * User EJB */ - @EJB(lookup = "java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") - private UserSessionBeanRemote userBean; + private static UserSessionBeanRemote USER_BEAN; /** * Default constructor @@ -48,6 +50,20 @@ public class JobsUserConverter 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/jjobs-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 JobsUserConverter 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/jjobs/validator/business/basicdata/JobsCompanyNameValidator.java b/src/java/org/mxchange/jjobs/validator/business/basicdata/JobsCompanyNameValidator.java index f922b8e8..c8f5d031 100644 --- a/src/java/org/mxchange/jjobs/validator/business/basicdata/JobsCompanyNameValidator.java +++ b/src/java/org/mxchange/jjobs/validator/business/basicdata/JobsCompanyNameValidator.java @@ -17,12 +17,14 @@ package org.mxchange.jjobs.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; @@ -35,18 +37,31 @@ import org.mxchange.jcoreee.validator.string.BaseStringValidator; public class JobsCompanyNameValidator 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/jjobs-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/jjobs-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 JobsCompanyNameValidator 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/jjobs/validator/emailaddress/JobsEmailAddressValidator.java b/src/java/org/mxchange/jjobs/validator/emailaddress/JobsEmailAddressValidator.java index ee114d89..0c99d953 100644 --- a/src/java/org/mxchange/jjobs/validator/emailaddress/JobsEmailAddressValidator.java +++ b/src/java/org/mxchange/jjobs/validator/emailaddress/JobsEmailAddressValidator.java @@ -18,12 +18,14 @@ package org.mxchange.jjobs.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; @@ -38,8 +40,7 @@ public class JobsEmailAddressValidator extends BaseStringValidator { /** * Contact session-scoped bean */ - @EJB (lookup = "java:global/jjobs-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") - private ContactSessionBeanRemote contactBean; + private static ContactSessionBeanRemote CONTACT_BEAN; /** * Email pattern @@ -64,6 +65,20 @@ public class JobsEmailAddressValidator 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/jjobs-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 JobsEmailAddressValidator 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/jjobs/validator/user/JobsUserIdValidator.java b/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java index cf383d76..4c6b0420 100644 --- a/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java +++ b/src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java @@ -17,12 +17,14 @@ package org.mxchange.jjobs.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 JobsUserIdValidator 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/jjobs-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 JobsUserIdValidator 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/jjobs-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 JobsUserIdValidator 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