]> git.mxchange.org Git - jfinancials-war.git/commitdiff
Please cherry-pick:
authorRoland Häder <roland@mxchange.org>
Sun, 25 Jun 2017 18:32:08 +0000 (20:32 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 25 Jun 2017 18:32:08 +0000 (20:32 +0200)
- always rely on "cached" lists rather than calling EJB for each request

Signed-off-by: Roland Häder <roland@mxchange.org>
src/java/org/mxchange/jfinancials/validator/emailaddress/FinancialsEmailAddressValidator.java

index 942dffe316e8ef29e7b017f908be37a156818c9f..7b8e296411378d99a2cca7662645092d5334807c 100644 (file)
@@ -17,6 +17,7 @@
 package org.mxchange.jfinancials.validator.emailaddress;
 
 import java.text.MessageFormat;
+import java.util.List;
 import java.util.regex.Pattern;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
@@ -49,6 +50,11 @@ public class FinancialsEmailAddressValidator extends BaseStringValidator impleme
         */
        private ContactSessionBeanRemote contactBean;
 
+       /**
+        * Cached list of all email addresses
+        */
+       private List<String> emailAddresses;
+
        /**
         * Default constructor
         */
@@ -90,6 +96,9 @@ public class FinancialsEmailAddressValidator extends BaseStringValidator impleme
 
                                        // Try to lookup
                                        this.contactBean = (ContactSessionBeanRemote) initialContext.lookup("java:global/jfinancials-ejb/contact!org.mxchange.jcontacts.contact.ContactSessionBeanRemote"); //NOI18N
+
+                                       // Get whole list of email addresses
+                                       this.emailAddresses = this.contactBean.getEmailAddressList();
                                } catch (final NamingException ex) {
                                        // Continue to throw it
                                        throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
@@ -101,13 +110,13 @@ public class FinancialsEmailAddressValidator extends BaseStringValidator impleme
                String clientId = component.getClientId();
 
                // Is the email address already registered?
-               if ((!clientId.endsWith("resendEmailAddress")) && (this.contactBean.isEmailAddressRegistered(emailAddress))) { //NOI18N
+               if ((!clientId.endsWith("resendEmailAddress")) && (this.emailAddresses.contains(emailAddress))) { //NOI18N
                        // Generate message
                        String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N
 
                        // No, then abort here
                        throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
-               } else if ((clientId.endsWith("resendEmailAddress")) && (!this.contactBean.isEmailAddressRegistered(emailAddress))) { //NOI18N
+               } else if ((clientId.endsWith("resendEmailAddress")) && (!this.emailAddresses.contains(emailAddress))) { //NOI18N
                        // Generate message
                        String message = MessageFormat.format("Email address {0} is not registered.", emailAddress); //NOI18N