/*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2017 - 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.landline;
-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.jphone.exceptions.PhoneEntityNotFoundException;
-import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote;
+import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewBean;
+import org.mxchange.jjobs.beans.phone.list.JobsPhoneListWebViewController;
+import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
/**
* Converter for land-line id <-> valid land-line number instance
/**
* Phone EJB
*/
- private static PhoneSessionBeanRemote PHONE_BEAN;
+ private static JobsPhoneListWebViewController PHONE_LIST_CONTROLLER;
@Override
public DialableLandLineNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (PHONE_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- PHONE_BEAN = (PhoneSessionBeanRemote) initial.lookup("java:global/jjobs-ejb/phone!org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not possible here: this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
// Return null
return null;
}
// Init instance
DialableLandLineNumber landLineNumber = null;
+ // Is the instance there?
+ if (null == PHONE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ PHONE_LIST_CONTROLLER = CDI.current().select(JobssPhoneListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
final Long landLineNumberId = Long.valueOf(submittedValue);
// Try to get mobile instance from it
- landLineNumber = PHONE_BEAN.findLandLineNumberById(landLineNumberId);
+ landLineNumber = PHONE_LIST_CONTROLLER.findLandLineNumberById(landLineNumberId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);