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=fe520537c04387e23f82a399f46931562b6d32fb;p=addressbook-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/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestBean.java index 51a65f58..39bfc1e8 100644 --- a/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestBean.java @@ -60,8 +60,8 @@ public class AddressbookBusinessDataWebRequestBean extends BaseAddressbookContro * 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/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java index e0d42fc2..fd20bd22 100644 --- a/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java @@ -54,8 +54,8 @@ public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookCon * 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/addressbook/beans/contact/AddressbookContactWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java index 995b6892..c5bca488 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java @@ -102,8 +102,8 @@ public class AddressbookContactWebRequestBean extends BaseAddressbookController * 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 AddressbookContactWebRequestBean extends BaseAddressbookController * 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/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestBean.java index 65bd07ce..8d56ad23 100644 --- a/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestBean.java @@ -69,8 +69,8 @@ public class AddressbookContactPhoneWebRequestBean extends BaseAddressbookContro * 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/addressbook/beans/country/AddressbookCountryWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestBean.java index 7247d375..5917b9cd 100644 --- a/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestBean.java @@ -57,8 +57,8 @@ public class AddressbookCountryWebRequestBean extends BaseAddressbookController * 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/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java index d0f72af1..1c6f5962 100644 --- a/src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java @@ -57,8 +57,8 @@ public class AddressbookMobileProviderWebRequestBean extends BaseAddressbookCont * "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/addressbook/beans/phone/AddressbookPhoneWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestBean.java index d94cbc2e..738436ef 100644 --- a/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestBean.java @@ -66,22 +66,22 @@ public class AddressbookPhoneWebRequestBean extends BaseAddressbookController im * 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/addressbook/beans/user/AddressbookUserWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestBean.java index cdf18df4..91c554d4 100644 --- a/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestBean.java @@ -119,8 +119,8 @@ public class AddressbookUserWebRequestBean extends BaseAddressbookController imp * 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 AddressbookUserWebRequestBean extends BaseAddressbookController imp * 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/addressbook/beans/user/activity/AddressbookUserActivityWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestBean.java index 1d6321b5..b70cd918 100644 --- a/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestBean.java @@ -79,8 +79,8 @@ public class AddressbookUserActivityWebRequestBean extends BaseAddressbookContro * "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/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestBean.java b/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestBean.java index b29bce50..a6b6a891 100644 --- a/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestBean.java +++ b/src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestBean.java @@ -79,8 +79,8 @@ public class AddressbookEmailChangeWebRequestBean extends BaseAddressbookControl * 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/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java b/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java index f6b80ea5..9e866c36 100644 --- a/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java +++ b/src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.addressbook.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.exceptions.basicdata.BusinessDataNotFoundException; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessDataSessionBeanRemote; @@ -37,8 +41,7 @@ public class AddressbookBusinessContactConverter implements Converter /** * CompanyEmployee EJB */ - @EJB (lookup = "java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.employee.CompanyEmployeeSessionBeanRemote") - private CompanyEmployeeSessionBeanRemote companyEmployeeBean; + private static CompanyEmployeeSessionBeanRemote COMPANY_EMPLOYEE_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class AddressbookCompanyEmployeeConverter 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/addressbook-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 AddressbookCompanyEmployeeConverter 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/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java b/src/java/org/mxchange/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java index e9f2b4e7..4526fb85 100644 --- a/src/java/org/mxchange/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java +++ b/src/java/org/mxchange/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.addressbook.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,8 +41,7 @@ public class AddressbookCompanyHeadquartersConverter implements Converter { /** * User EJB */ - @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") - private ContactSessionBeanRemote contactBean; + private static ContactSessionBeanRemote CONTACT_BEAN; /** * Default constructor @@ -48,6 +51,20 @@ public class AddressbookContactConverter 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/addressbook-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 AddressbookContactConverter implements Converter { Long contactId = Long.valueOf(submittedValue); // Try to get user instance from it - contact = this.contactBean.findContactById(contactId); + contact = CONTACT_BEAN.findContactById(contactId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); diff --git a/src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java b/src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java index 667e43cf..15df38e1 100644 --- a/src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java +++ b/src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java @@ -18,12 +18,16 @@ package org.mxchange.addressbook.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,8 +42,7 @@ public class AddressbookCountryConverter implements Converter { /** * Country bean */ - @EJB (lookup = "java:global/addressbook-ejb/country!org.mxchange.jcountry.data.CountrySingletonBeanRemote") - private CountrySingletonBeanRemote countryBean; + private static CountrySingletonBeanRemote COUNTRY_BEAN; /** * Default constructor @@ -49,6 +52,20 @@ public class AddressbookCountryConverter 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/addressbook-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 AddressbookCountryConverter 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/addressbook/converter/fax/AddressbookFaxNumberConverter.java b/src/java/org/mxchange/addressbook/converter/fax/AddressbookFaxNumberConverter.java index 72fa8328..c58556f9 100644 --- a/src/java/org/mxchange/addressbook/converter/fax/AddressbookFaxNumberConverter.java +++ b/src/java/org/mxchange/addressbook/converter/fax/AddressbookFaxNumberConverter.java @@ -16,12 +16,16 @@ */ package org.mxchange.addressbook.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,8 +41,7 @@ public class AddressbookFaxNumberConverter implements Converter { /** * User EJB */ - @EJB(lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") - private UserSessionBeanRemote userBean; + private static UserSessionBeanRemote USER_BEAN; /** * Default constructor @@ -48,6 +50,20 @@ public class AddressbookUserConverter 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/addressbook-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 AddressbookUserConverter 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/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java b/src/java/org/mxchange/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java index 9268f034..b939eb73 100644 --- a/src/java/org/mxchange/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java +++ b/src/java/org/mxchange/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java @@ -17,12 +17,14 @@ package org.mxchange.addressbook.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.model.basicdata.BusinessDataSessionBeanRemote; import org.mxchange.jcoreee.validator.string.BaseStringValidator; @@ -35,18 +37,31 @@ import org.mxchange.jcoreee.validator.string.BaseStringValidator; public class AddressbookCompanyNameValidator 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/addressbook-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/addressbook-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 +89,8 @@ public class AddressbookCompanyNameValidator extends BaseStringValidator { checkExisting = Boolean.parseBoolean((String) attribute); } - Boolean nameExists = this.basicDataBean.isCompanyNameUsed(companyName); + // Check if name is already used + Boolean nameExists = BASIC_DATA_BEAN.isCompanyNameUsed(companyName); // Is the user id valid? if ((!nameExists) && (checkExisting)) { diff --git a/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java b/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java index c8ed7676..f11e40a7 100644 --- a/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java +++ b/src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java @@ -18,12 +18,14 @@ package org.mxchange.addressbook.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 AddressbookEmailAddressValidator extends BaseStringValidator { /** * Contact session-scoped bean */ - @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote") - private ContactSessionBeanRemote contactBean; + private static ContactSessionBeanRemote CONTACT_BEAN; /** * Email pattern @@ -64,7 +65,20 @@ public class AddressbookEmailAddressValidator extends BaseStringValidator { @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/addressbook-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 +89,6 @@ public class AddressbookEmailAddressValidator 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 +99,6 @@ public class AddressbookEmailAddressValidator 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 +133,7 @@ public class AddressbookEmailAddressValidator 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/addressbook/validator/user/AddressbookUserIdValidator.java b/src/java/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java index 40739a9b..7c4aac1d 100644 --- a/src/java/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java +++ b/src/java/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java @@ -17,12 +17,14 @@ package org.mxchange.addressbook.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 AddressbookUserIdValidator 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/addressbook-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 AddressbookUserIdValidator 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/addressbook-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 AddressbookUserIdValidator 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) {