]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/converter/mobile/JobsMobileNumberConverter.java
Please cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / converter / mobile / JobsMobileNumberConverter.java
index 9476eec7fd56d5a16513734713f57684df21c11a..b31921fffb10d4da2bc782a57ab16c0608a1c56c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2020 Free Software Foundation
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as
  */
 package org.mxchange.jjobs.converter.mobile;
 
-import java.text.MessageFormat;
+import javax.enterprise.inject.spi.CDI;
 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.jphone.exceptions.PhoneEntityNotFoundException;
-import org.mxchange.jphone.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote;
+import org.mxchange.jjobs.beans.mobile.list.JobsMobileListWebViewBean;
+import org.mxchange.jjobs.beans.mobile.list.JobsMobileListWebViewController;
+import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
 
 /**
  * Converter for mobile id <-> valid mobile instance
  * <p>
  * @author Roland Häder<roland@mxchange.org>
  */
-@FacesConverter (value = "MobileNumberConverter")
+@FacesConverter ("MobileNumberConverter")
 public class JobsMobileNumberConverter implements Converter<DialableMobileNumber> {
 
        /**
         * Phone EJB
         */
-       private static PhoneSessionBeanRemote PHONE_BEAN;
-
-       /**
-        * Default constructor
-        */
-       public JobsMobileNumberConverter () {
-       }
+       private static JobsMobileListWebViewController MOBILE_LIST_CONTROLLER;
 
        @Override
        public DialableMobileNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
                // Is the value null or empty?
                if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
-                       // Warning message
-                       // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
                        // Return null
                        return null;
                }
 
-               // Is the bean there?
-               // @TODO Requires this synchronization or is it (sync) confusing the container?
-               if (null == JobsMobileNumberConverter.PHONE_BEAN) {
-                       // Try to get it
-                       try {
-                               // Get initial context
-                               Context initialContext = new InitialContext();
-
-                               // ... and user controller
-                               JobsMobileNumberConverter.PHONE_BEAN = (PhoneSessionBeanRemote) initialContext.lookup("java:global/jjobs-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote"); //NOI18N
-                       } catch (final NamingException ex) {
-                               // Continue to throw it
-                               throw new ConverterException(MessageFormat.format("initialContext.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N
-                       }
-               }
-
                // Init instance
                DialableMobileNumber mobileNumber = null;
 
+               // Is the instance there?
+               if (null == MOBILE_LIST_CONTROLLER) {
+                       // Get bean from CDI directly
+                       MOBILE_LIST_CONTROLLER = CDI.current().select(JobssMobileListWebViewBean.class).get();
+               }
+
                try {
                        // Try to parse the value as long
-                       Long mobileNumberId = Long.valueOf(submittedValue);
+                       final Long mobileNumberId = Long.valueOf(submittedValue);
 
                        // Try to get mobile instance from it
-                       mobileNumber = JobsMobileNumberConverter.PHONE_BEAN.findMobileNumberById(mobileNumberId);
+                       mobileNumber = MOBILE_LIST_CONTROLLER.findMobileNumberById(mobileNumberId);
                } catch (final NumberFormatException ex) {
                        // Throw again
                        throw new ConverterException(ex);
-               } catch (final PhoneEntityNotFoundException ex) {
+               } catch (final MobileEntityNotFoundException ex) {
                        // Debug message
                        // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
                }
@@ -105,7 +84,7 @@ public class JobsMobileNumberConverter implements Converter<DialableMobileNumber
                }
 
                // Return id number
-               return String.valueOf(value.getPhoneId());
+               return String.valueOf(value.getMobileId());
        }
 
 }