]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/validator/user/JobsUserIdValidator.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / validator / user / JobsUserIdValidator.java
index c56a07faba339bc258478ef9704214aeb1442f2c..267a071f0c2311ad7bc04de6ea78e1f17117fcd1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2018 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 package org.mxchange.jjobs.validator.user;
 
 import java.text.MessageFormat;
+import javax.enterprise.inject.spi.CDI;
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
-import javax.faces.convert.ConverterException;
 import javax.faces.validator.FacesValidator;
-import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcoreee.validator.number.BaseLongValidator;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.jcoreee.validator.number.BaseNumberValidator;
+import org.mxchange.jjobs.beans.user.JobsUserWebRequestBean;
+import org.mxchange.jjobs.beans.user.JobsUserWebRequestController;
 
 /**
  * A validator for user ids
@@ -36,54 +33,37 @@ import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
  * @author Roland Häder<roland@mxchange.org>
  */
 @FacesValidator ("UserIdValidator")
-public class JobsUserIdValidator extends BaseLongValidator implements Validator {
+public class JobsUserIdValidator extends BaseNumberValidator {
 
        /**
-        * Serial number
+        * User backing bean
         */
-       private static final long serialVersionUID = 12_869_569_314_764_690L;
+       private static JobsUserWebRequestController USER_CONTROLLER;
 
        /**
-        * Remote bean
-        */
-       private UserSessionBeanRemote userBean;
-
-       /**
-        * Initialization of this converter
+        * Serial number
         */
-       public JobsUserIdValidator () {
-       }
+       private static final long serialVersionUID = 12_869_569_314_764_690L;
 
        @Override
        public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
                // All accepted, required fields
-               String[] requiredFields = {"userId"}; //NOI18N
+               final String[] requiredFields = {"userId"}; //NOI18N
 
                // Pre-validation (example: not null, not a string, empty string ...)
                super.preValidate(context, component, value, requiredFields, false);
 
-               // Cast value
-               Long userId = (Long) value;
-
-               synchronized (this) {
-                       // Is the EJB instanciated?
-                       if (null == this.userBean) {
-                               // Try to get it
-                               try {
-                                       // Get initial context
-                                       Context initialContext = new InitialContext();
-
-                                       // ... and user controller
-                                       this.userBean = (UserSessionBeanRemote) initialContext.lookup("java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote"); //NOI18N
-                               } catch (final NamingException ex) {
-                                       // Continue to throw it
-                                       throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-                               }
-                       }
+               // Is the instance there?
+               if (null == USER_CONTROLLER) {
+                       // Get bean from CDI directly
+                       USER_CONTROLLER = CDI.current().select(JobsUserWebRequestBean.class).get();
                }
 
+               // Cast value
+               final Long userId = (Long) value;
+
                // Define variable
-               Boolean ifUserExists = this.userBean.ifUserIdExists(userId);
+               final Boolean ifUserExists = USER_CONTROLLER.ifUserIdExists(userId);
 
                // Is the user id valid?
                if (!ifUserExists) {