]> git.mxchange.org Git - addressbook-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 3 Sep 2017 02:40:58 +0000 (04:40 +0200)
committerRoland Häder <roland@mxchange.org>
Sat, 9 Sep 2017 20:08:39 +0000 (22:08 +0200)
- 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 <roland@mxchange.org>
22 files changed:
src/java/org/mxchange/addressbook/beans/business/basicdata/AddressbookBusinessDataWebRequestBean.java
src/java/org/mxchange/addressbook/beans/business/employee/AddressbookCompanyEmployeeWebRequestBean.java
src/java/org/mxchange/addressbook/beans/contact/AddressbookContactWebRequestBean.java
src/java/org/mxchange/addressbook/beans/contact/phone/AddressbookContactPhoneWebRequestBean.java
src/java/org/mxchange/addressbook/beans/country/AddressbookCountryWebRequestBean.java
src/java/org/mxchange/addressbook/beans/mobileprovider/AddressbookMobileProviderWebRequestBean.java
src/java/org/mxchange/addressbook/beans/phone/AddressbookPhoneWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/AddressbookUserWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/activity/AddressbookUserActivityWebRequestBean.java
src/java/org/mxchange/addressbook/beans/user/email_address/AddressbookEmailChangeWebRequestBean.java
src/java/org/mxchange/addressbook/converter/business/basicdata/AddressbookBusinessContactConverter.java
src/java/org/mxchange/addressbook/converter/business/company_employee/AddressbookCompanyEmployeeConverter.java
src/java/org/mxchange/addressbook/converter/business/headquarters/AddressbookCompanyHeadquartersConverter.java
src/java/org/mxchange/addressbook/converter/contact/AddressbookContactConverter.java
src/java/org/mxchange/addressbook/converter/country/AddressbookCountryConverter.java
src/java/org/mxchange/addressbook/converter/fax/AddressbookFaxNumberConverter.java
src/java/org/mxchange/addressbook/converter/landline/AddressbookLandLineNumberConverter.java
src/java/org/mxchange/addressbook/converter/mobile/AddressbookMobileNumberConverter.java
src/java/org/mxchange/addressbook/converter/user/AddressbookUserConverter.java
src/java/org/mxchange/addressbook/validator/business/basicdata/AddressbookCompanyNameValidator.java
src/java/org/mxchange/addressbook/validator/emailaddress/AddressbookEmailAddressValidator.java
src/java/org/mxchange/addressbook/validator/user/AddressbookUserIdValidator.java

index 51a65f58373eb99178798cf948ff01619b00d229..39bfc1e8cc5deccd0d269d02bf38d593e2cb980a 100644 (file)
@@ -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<Long, BusinessBasicData> basicDataCache;
+       @NamedCache (cacheName = "basicDataCache")
+       private Cache<Long, BusinessBasicData> basicDataCache;
 
        /**
         * EJB for general basic business data purposes
index e0d42fc24256bcb8ab7ae312c12d992d0b463a80..fd20bd22a225cc4477ecc1b2edd42724ea15e566 100644 (file)
@@ -54,8 +54,8 @@ public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookCon
         * List of all company employees
         */
        @Inject
-       @NamedCache (cacheName = "companyEmployeeCache", managementEnabled = true)
-       private transient Cache<Long, Employee> companyEmployeeCache;
+       @NamedCache (cacheName = "companyEmployeeCache")
+       private Cache<Long, Employee> companyEmployeeCache;
 
        /**
         * Default constructor
index 995b6892ce61f9af0e2a1fc958e05caa260069f7..c5bca488862a0b8e9a7b8c7835bcc21a1b81ba3d 100644 (file)
@@ -102,8 +102,8 @@ public class AddressbookContactWebRequestBean extends BaseAddressbookController
         * Contact list
         */
        @Inject
-       @NamedCache (cacheName = "contactsCache", managementEnabled = true)
-       private transient Cache<Long, Contact> contactsCache;
+       @NamedCache (cacheName = "contactsCache")
+       private Cache<Long, Contact> contactsCache;
 
        /**
         * Country instance
@@ -119,8 +119,8 @@ public class AddressbookContactWebRequestBean extends BaseAddressbookController
         * Email address list
         */
        @Inject
-       @NamedCache (cacheName = "emailAddressCache", managementEnabled = true)
-       private transient Cache<Long, String> emailAddressCache;
+       @NamedCache (cacheName = "emailAddressCache")
+       private Cache<Long, String> emailAddressCache;
 
        /**
         * Email address repeated
index 65bd07ce2ef2256e3fd27b99e9f166ae2bde61ad..8d56ad23a83f509a55aaa9370d672b1ec24446fa 100644 (file)
@@ -69,8 +69,8 @@ public class AddressbookContactPhoneWebRequestBean extends BaseAddressbookContro
         * relationship (one contact, many numbers).
         */
        @Inject
-       @NamedCache (cacheName = "contactsPhoneCache", managementEnabled = true)
-       private transient Cache<DialableNumber, List<Contact>> contactsPhoneCache;
+       @NamedCache (cacheName = "contactsPhoneCache")
+       private Cache<DialableNumber, List<Contact>> contactsPhoneCache;
 
        /**
         * fax number
index 7247d3756840ae058b45788bf6d2c1aa40a7dc97..5917b9cde4f5735391316fe91950070d565f8892 100644 (file)
@@ -57,8 +57,8 @@ public class AddressbookCountryWebRequestBean extends BaseAddressbookController
         * List of all countries
         */
        @Inject
-       @NamedCache (cacheName = "countryCache", managementEnabled = true)
-       private transient Cache<Long, Country> countryCache;
+       @NamedCache (cacheName = "countryCache")
+       private Cache<Long, Country> countryCache;
 
        /**
         * Default constructor
index d0f72af1e75e1d3c84c380320a44f7ceebc7b72f..1c6f5962c417f34c022e6db3746ca3657fade049 100644 (file)
@@ -57,8 +57,8 @@ public class AddressbookMobileProviderWebRequestBean extends BaseAddressbookCont
         * "Cached" list of mobile providers
         */
        @Inject
-       @NamedCache (cacheName = "mobileProviderCache", managementEnabled = true)
-       private transient Cache<Long, MobileProvider> mobileProviderCache;
+       @NamedCache (cacheName = "mobileProviderCache")
+       private Cache<Long, MobileProvider> mobileProviderCache;
 
        /**
         * Default constructor
index d94cbc2eef08acebc8f469e10b6330be7b3d7aa1..738436ef202c04ef4c75a513303c5b53b072074b 100644 (file)
@@ -66,22 +66,22 @@ public class AddressbookPhoneWebRequestBean extends BaseAddressbookController im
         * All fax numbers
         */
        @Inject
-       @NamedCache (cacheName = "faxNumberCache", managementEnabled = true)
-       private transient Cache<Long, DialableFaxNumber> faxNumberCache;
+       @NamedCache (cacheName = "faxNumberCache")
+       private Cache<Long, DialableFaxNumber> faxNumberCache;
 
        /**
         * All land-line numbers
         */
        @Inject
-       @NamedCache (cacheName = "landLineNumberCache", managementEnabled = true)
-       private transient Cache<Long, DialableLandLineNumber> landLineNumberCache;
+       @NamedCache (cacheName = "landLineNumberCache")
+       private Cache<Long, DialableLandLineNumber> landLineNumberCache;
 
        /**
         * All mobile numbers
         */
        @Inject
-       @NamedCache (cacheName = "mobileNumberCache", managementEnabled = true)
-       private transient Cache<Long, DialableMobileNumber> mobileNumberCache;
+       @NamedCache (cacheName = "mobileNumberCache")
+       private Cache<Long, DialableMobileNumber> mobileNumberCache;
 
        /**
         * General EJB for phone numbers
index cdf18df4761639b440801ce021d6176bdd3d429f..91c554d459557362aa8cf89e99285f6efe82f2ae 100644 (file)
@@ -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<Long, User> userCache;
+       @NamedCache (cacheName = "userCache")
+       private Cache<Long, User> 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<Long, String> userNameCache;
+       @NamedCache (cacheName = "userNameCache")
+       private Cache<Long, String> userNameCache;
 
        /**
         * User password (clear-text from web form)
index 1d6321b5c7469a047be6c10d83e201c48ba91a86..b70cd918cae8c4bb10197172560af6f343140107 100644 (file)
@@ -79,8 +79,8 @@ public class AddressbookUserActivityWebRequestBean extends BaseAddressbookContro
         * "Cache" for activity log per user
         */
        @Inject
-       @NamedCache (cacheName = "userActivityCache", managementEnabled = true)
-       private transient Cache<User, List<LogableUserActivity>> userActivityCache;
+       @NamedCache (cacheName = "userActivityCache")
+       private Cache<User, List<LogableUserActivity>> userActivityCache;
 
        /**
         * Default constructor
index b29bce50e713eec9388d975b2d6f38fdfb58b277..a6b6a89181a08744ce51d88f4c97367a4a82cf05 100644 (file)
@@ -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<String, Boolean> queuedEmailCache;
+       @NamedCache (cacheName = "queuedEmailCache")
+       private Cache<String, Boolean> queuedEmailCache;
 
        /**
         * Login controller (bean)
index f6b80ea54a0b2be0cc3fd85fa32c2cd22236b45f..9e866c364d67086e09e72f7c96234b9003b74f00 100644 (file)
  */
 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<BusinessBa
        /**
         * Business contact EJB
         */
-       @EJB (lookup = "java:global/addressbook-ejb/businessData!org.mxchange.jcontactsbusiness.basicdata.BusinessDataSessionBeanRemote")
-       private BusinessDataSessionBeanRemote basicDataBean;
+       private static BusinessDataSessionBeanRemote BASIC_DATA_BEAN;
 
        /**
         * Default constructor
@@ -48,6 +51,20 @@ public class AddressbookBusinessContactConverter implements Converter<BusinessBa
 
        @Override
        public BusinessBasicData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+               // 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);
+                       }
+               }
+
                // Is the value null or empty?
                if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
                        // Warning message
@@ -65,7 +82,7 @@ public class AddressbookBusinessContactConverter implements Converter<BusinessBa
                        Long basicDataId = Long.valueOf(submittedValue);
 
                        // Try to get user instance from it
-                       businessContact = this.basicDataBean.findBasicDataById(basicDataId);
+                       businessContact = BASIC_DATA_BEAN.findBasicDataById(basicDataId);
                } catch (final NumberFormatException ex) {
                        // Throw again
                        throw new ConverterException(ex);
index b8376e475798b5b6430597d88290132b44b3c36c..e4eaecd4755e52b19f0bb81b852a3a10777d5df1 100644 (file)
  */
 package org.mxchange.addressbook.converter.business.company_employee;
 
-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.employee.CompanyEmployeeNotFoundException;
 import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote;
 import org.mxchange.jcontactsbusiness.model.employee.Employee;
@@ -37,8 +41,7 @@ public class AddressbookCompanyEmployeeConverter implements Converter<Employee>
        /**
         * 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<Employee>
 
        @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<Employee>
                        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);
index e9f2b4e7cd24779a1f22bcdbd083914521ed33e0..4526fb858dc3b411bf1a16cddd379637073bd057 100644 (file)
  */
 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<Headqu
        /**
         * CompanyEmployee EJB
         */
-       @EJB (lookup = "java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersSessionBeanRemote")
-       private CompanyHeadquartersSessionBeanRemote companyHeadquartersBean;
+       private static CompanyHeadquartersSessionBeanRemote COMPANY_HEADQUARTERS_BEAN;
 
        /**
         * Default constructor
@@ -48,6 +51,20 @@ public class AddressbookCompanyHeadquartersConverter implements Converter<Headqu
 
        @Override
        public HeadquartersData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+               // Is the instance there?
+               if (COMPANY_HEADQUARTERS_BEAN == null) {
+                       try {
+                               // Not yet, attempt lookup
+                               Context initial = new InitialContext();
+
+                               // Lookup EJB
+                               COMPANY_HEADQUARTERS_BEAN = (CompanyHeadquartersSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.headquarters.CompanyHeadquartersSessionBeanRemote");
+                       } 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 AddressbookCompanyHeadquartersConverter implements Converter<Headqu
                        Long headquartersId = Long.valueOf(submittedValue);
 
                        // Try to get user instance from it
-                       companyHeadquarters = this.companyHeadquartersBean.findCompanyHeadquartersById(headquartersId);
+                       companyHeadquarters = COMPANY_HEADQUARTERS_BEAN.findCompanyHeadquartersById(headquartersId);
                } catch (final NumberFormatException ex) {
                        // Throw again
                        throw new ConverterException(ex);
index 0db57189d119711a522cc7df0477627eb9b58ccd..240af7dffaef9d9aaff0b9007c2673bbe88e32cd 100644 (file)
  */
 package org.mxchange.addressbook.converter.contact;
 
-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.jcontacts.exceptions.ContactNotFoundException;
 import org.mxchange.jcontacts.model.contact.Contact;
 import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
@@ -37,8 +41,7 @@ public class AddressbookContactConverter implements Converter<Contact> {
        /**
         * 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<Contact> {
 
        @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<Contact> {
                        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);
index 667e43cfac068050423e91595099954c0d02eefe..15df38e1c4506db02596a6ee001b73ec5a851e66 100644 (file)
@@ -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> {
        /**
         * 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<Country> {
 
        @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<Country> {
                }
 
                // Get full list
-               List<Country> countryList = this.countryBean.allCountries();
+               List<Country> countryList = COUNTRY_BEAN.allCountries();
 
                // Init value
                Country country = null;
index 72fa8328712d2497be189cc951213c3813f7aa72..c58556f99ed0090e7c5c3c3f6fb12d2ce613a0b5 100644 (file)
  */
 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<DialableFaxNumbe
        /**
         * Phone EJB
         */
-       @EJB(lookup = "java:global/addressbook-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote")
-       private PhoneSessionBeanRemote phoneBean;
+       private static PhoneSessionBeanRemote PHONE_BEAN;
 
        /**
         * Default constructor
@@ -48,6 +51,20 @@ public class AddressbookFaxNumberConverter implements Converter<DialableFaxNumbe
 
        @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/addressbook-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 AddressbookFaxNumberConverter implements Converter<DialableFaxNumbe
                        // 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);
index 98b88170f6b5498561751165da14c14e897fde40..cd918ead2813fdbb99f39aceec19903b0e3d5f75 100644 (file)
  */
 package org.mxchange.addressbook.converter.landline;
 
-import javax.ejb.EJB;
+import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 import javax.faces.convert.Converter;
 import javax.faces.convert.ConverterException;
 import javax.faces.convert.FacesConverter;
+import javax.faces.validator.ValidatorException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;
 import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
 import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
@@ -37,8 +41,7 @@ public class AddressbookLandLineNumberConverter implements Converter<DialableLan
        /**
         * Phone EJB
         */
-       @EJB(lookup = "java:global/addressbook-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote")
-       private PhoneSessionBeanRemote phoneBean;
+       private static PhoneSessionBeanRemote PHONE_BEAN;
 
        /**
         * Default constructor
@@ -48,6 +51,20 @@ public class AddressbookLandLineNumberConverter implements Converter<DialableLan
 
        @Override
        public DialableLandLineNumber 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/addressbook-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);
+                       }
+               }
+
                // Is the value null or empty?
                if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
                        // Warning message
@@ -65,7 +82,7 @@ public class AddressbookLandLineNumberConverter implements Converter<DialableLan
                        Long landLineNumberId = Long.valueOf(submittedValue);
 
                        // Try to get mobile instance from it
-                       landLineNumber = this.phoneBean.findLandLineNumberById(landLineNumberId);
+                       landLineNumber = PHONE_BEAN.findLandLineNumberById(landLineNumberId);
                } catch (final NumberFormatException ex) {
                        // Throw again
                        throw new ConverterException(ex);
index d92263da0488db019afa63326adafb52b5ef66f0..c56efdc1c87e82f87759750fc130eecc97f146a7 100644 (file)
  */
 package org.mxchange.addressbook.converter.mobile;
 
-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.mobile.DialableMobileNumber;
 import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
@@ -37,8 +41,7 @@ public class AddressbookMobileNumberConverter implements Converter<DialableMobil
        /**
         * Phone EJB
         */
-       @EJB (lookup = "java:global/addressbook-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote")
-       private PhoneSessionBeanRemote phoneBean;
+       private static PhoneSessionBeanRemote PHONE_BEAN;
 
        /**
         * Default constructor
@@ -48,6 +51,20 @@ public class AddressbookMobileNumberConverter implements Converter<DialableMobil
 
        @Override
        public DialableMobileNumber 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/addressbook-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);
+                       }
+               }
+
                // Is the value null or empty?
                if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
                        // Warning message
@@ -65,7 +82,7 @@ public class AddressbookMobileNumberConverter implements Converter<DialableMobil
                        Long mobileId = Long.valueOf(submittedValue);
 
                        // Try to get mobile instance from it
-                       mobile = this.phoneBean.findMobileNumberById(mobileId);
+                       mobile = PHONE_BEAN.findMobileNumberById(mobileId);
                } catch (final NumberFormatException ex) {
                        // Throw again
                        throw new ConverterException(ex);
index cde0291c89340098e6e5bedc4c45c1d5c48c2cc1..f47729c3da7974004801c0a47f40ced01d39d27b 100644 (file)
  */
 package org.mxchange.addressbook.converter.user;
 
-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.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 import org.mxchange.jusercore.exceptions.UserNotFoundException;
 import org.mxchange.jusercore.model.user.User;
 import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
@@ -37,8 +40,7 @@ public class AddressbookUserConverter implements Converter<User> {
        /**
         * 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<User> {
 
        @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<User> {
                        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);
index 9268f03459fe1aa7d4a6abe208ff124f5f542fe4..b939eb7335fa545140db9160fc205d2c57f75d9e 100644 (file)
 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)) {
index c8ed7676cea977b6c97c09bdc596e753891baf82..f11e40a773f14059510310d7b3758dcb9b77e72b 100644 (file)
@@ -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
index 40739a9be5051059205dd7b21281e48475b1af90..7c4aac1d1da1a17da83a34922e1b52d3f38ba8a1 100644 (file)
 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) {