]> git.mxchange.org Git - pizzaservice-war.git/blobdiff - src/java/org/mxchange/pizzaapplication/validator/user/PizzaUserIdValidator.java
Please cherry-pick:
[pizzaservice-war.git] / src / java / org / mxchange / pizzaapplication / validator / user / PizzaUserIdValidator.java
index 57a8f6ec65258027b852b1814d22cb4c575c512f..abde9cee486a23d72a1d80dec6136b4b279d5a76 100644 (file)
 package org.mxchange.pizzaapplication.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 PizzaUserIdValidator extends BaseNumberValidator {
 
        /**
-        * Serial number
+        * Remote bean
         */
-       private static final long serialVersionUID = 12_869_569_314_764_690L;
+       private static UserSessionBeanRemote USER_BEAN;
 
        /**
-        * Remote bean
+        * Serial number
         */
-       @EJB (lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
-       private UserSessionBeanRemote userBean;
+       private static final long serialVersionUID = 12_869_569_314_764_690L;
 
        /**
         * Default constructor
@@ -53,6 +54,20 @@ public class PizzaUserIdValidator extends BaseNumberValidator {
 
        @Override
        public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+               // Is the instance there?
+               if (USER_BEAN == null) {
+                       try {
+                               // Not yet, attempt lookup
+                               Context initial = new InitialContext();
+
+                               // Lookup EJB
+                               USER_BEAN = (UserSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote");
+                       } catch (final NamingException ex) {
+                               // Throw it again
+                               throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
+                       }
+               }
+
                // All accepted, required fields
                String[] requiredFields = {"userId"}; //NOI18N
 
@@ -63,7 +78,7 @@ public class PizzaUserIdValidator 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) {