]> git.mxchange.org Git - jjobs-war.git/blobdiff - src/java/org/mxchange/jjobs/converter/business/opening_time/JobsCompanyOpeningTimeConverter.java
Don't cherry-pick:
[jjobs-war.git] / src / java / org / mxchange / jjobs / converter / business / opening_time / JobsCompanyOpeningTimeConverter.java
index c948d6f0b720210c029907a6d9bc685923d66352..2d0a0c3266d41a1b21eaca358cbfabafb1f0b7b0 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.business.opening_time;
 
-import javax.faces.application.FacesMessage;
+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.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException;
 import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
-import org.mxchange.jjobs.beans.business.opening_time.JobsOpeningTimeWebRequestBean;
-import org.mxchange.jjobs.beans.business.opening_time.JobsOpeningTimeWebRequestController;
+import org.mxchange.jjobs.beans.business.opening_time.list.JobsOpeningTimeListWebViewBean;
+import org.mxchange.jjobs.beans.business.opening_time.list.JobsOpeningTimeListWebViewController;
 
 /**
  * Converter for opening time id <-> instance
@@ -42,24 +38,10 @@ public class JobsCompanyOpeningTimeConverter implements Converter<OpeningTime> {
        /**
         * Opening time backing bean
         */
-       private static JobsOpeningTimeWebRequestController OPENING_TIMES_CONTROLLER;
+       private static JobsOpeningTimeListWebViewController OPENING_TIMES_LIST_CONTROLLER;
 
        @Override
        public OpeningTime getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
-               // Is the instance there?
-               if (OPENING_TIMES_CONTROLLER == null) {
-                       try {
-                               // Not yet, attempt lookup
-                               final Context initial = new InitialContext();
-
-                               // Lookup EJB
-                               OPENING_TIMES_CONTROLLER = (JobsOpeningTimeWebRequestController) initial.lookup(String.format("java:module/%s", JobsOpeningTimeWebRequestBean.class.getSimpleName())); //NOI18N
-                       } catch (final NamingException ex) {
-                               // Throw it again
-                               throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup backing bean", ex.getMessage()), ex); //NOI18N
-                       }
-               }
-
                // Is the value null or empty?
                if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
                        // Warning message
@@ -74,10 +56,16 @@ public class JobsCompanyOpeningTimeConverter implements Converter<OpeningTime> {
 
                try {
                        // Try to parse the value as long
-                       final Long openingId = Long.valueOf(submittedValue);
+                       final Long openingTimeId = Long.valueOf(submittedValue);
+
+                       // Is the instance there?
+                       if (null == OPENING_TIMES_LIST_CONTROLLER) {
+                               // Get bean from CDI directly
+                               OPENING_TIMES_LIST_CONTROLLER = CDI.current().select(JobsOpeningTimeListWebViewBean.class).get();
+                       }
 
                        // Try to get user instance from it
-                       openingTime = OPENING_TIMES_CONTROLLER.findOpeningTimeById(openingId);
+                       openingTime = OPENING_TIMES_LIST_CONTROLLER.findOpeningTimeById(openingTimeId);
                } catch (final NumberFormatException ex) {
                        // Throw again
                        throw new ConverterException(ex);
@@ -99,7 +87,7 @@ public class JobsCompanyOpeningTimeConverter implements Converter<OpeningTime> {
                }
 
                // Return id number
-               return String.valueOf(value.getOpeningId());
+               return String.valueOf(value.getOpeningTimeId());
        }
 
 }