X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2Fjava%2Forg%2Fmxchange%2Fjjobs%2Fconverter%2Flandline%2FJobsLandLineNumberConverter.java;h=ed7f613e9b1d0caf93007a6479a9dbda3b4d996f;hb=88344c201dccb8ccc2dec09190ab3efd596ef210;hp=18414be57cab6528491b5a96d87916b222a55c6d;hpb=27100e7dfbaee33ce63dd6b3c7e394115b24031f;p=jjobs-war.git diff --git a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java index 18414be5..ed7f613e 100644 --- a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java @@ -16,41 +16,38 @@ */ package org.mxchange.jjobs.converter.landline; -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.DialableNumber; -import org.mxchange.jphone.phonenumbers.landline.DialableLandLineNumber; -import org.mxchange.jphone.phonenumbers.phone.PhoneSessionBeanRemote; +import org.mxchange.jjobs.beans.phone.JobsPhoneWebRequestBean; +import org.mxchange.jjobs.beans.phone.JobsPhoneWebRequestController; +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 *

* @author Roland Häder */ -@FacesConverter (value = "LandLineNumberConverter") -public class JobsLandLineNumberConverter implements Converter { +@FacesConverter ("LandLineNumberConverter") +public class JobsLandLineNumberConverter implements Converter { /** * Phone EJB */ - private static PhoneSessionBeanRemote PHONE_BEAN; - - /** - * Initialization of this converter - */ - public JobsLandLineNumberConverter () { - } + private static JobsPhoneWebRequestController PHONE_CONTROLLER; @Override - public Object getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + public DialableLandLineNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (PHONE_CONTROLLER == null) { + // Get bean from CDI directly + PHONE_CONTROLLER = CDI.current().select(JobsPhoneWebRequestBean.class).get(); + } + // Is the value null or empty? if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { // Warning message @@ -60,31 +57,15 @@ public class JobsLandLineNumberConverter implements Converter { return null; } - // Is the bean there? - // @TODO Requires this synchronization or is it (sync) confusing the container? - if (null == JobsLandLineNumberConverter.PHONE_BEAN) { - // Try to get it - try { - // Get initial context - Context initialContext = new InitialContext(); - - // ... and user controller - JobsLandLineNumberConverter.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 RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N - } - } - // Init instance DialableLandLineNumber landLineNumber = null; try { // Try to parse the value as long - Long landLineNumberId = Long.valueOf(submittedValue); + final Long landLineNumberId = Long.valueOf(submittedValue); // Try to get mobile instance from it - landLineNumber = JobsLandLineNumberConverter.PHONE_BEAN.findLandLineNumberById(landLineNumberId); + landLineNumber = PHONE_CONTROLLER.findLandLineNumberById(landLineNumberId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); @@ -98,18 +79,15 @@ public class JobsLandLineNumberConverter implements Converter { } @Override - public String getAsString (final FacesContext context, final UIComponent component, final Object value) { + public String getAsString (final FacesContext context, final UIComponent component, final DialableLandLineNumber value) { // Is the object null? - if ((null == value) || ((String.valueOf(value)).isEmpty())) { + if ((null == value) || (String.valueOf(value).isEmpty())) { // Is null return ""; //NOI18N - } else if (!(value instanceof DialableNumber)) { - // Not same interface - throw new IllegalArgumentException(MessageFormat.format("value {0} does not implement DialableNumber.", value)); //NOI18N } - // Return category id - return String.valueOf(((DialableNumber) value).getPhoneId()); + // Return id number + return String.valueOf(value.getPhoneId()); } }