import java.util.List;
import java.util.Objects;
-import javax.ejb.EJB;
+import javax.faces.application.FacesMessage;
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.model.phonenumbers.mobileprovider.MobileProvider;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote;
/**
* Mobile provider bean
*/
- @EJB(lookup = "java:global/jfinancials-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote")
- private MobileProviderSingletonBeanRemote mobileProviderBean;
-
- /**
- * Default constructor
- */
- public PizzaMobileProviderConverter () {
- }
+ private static MobileProviderSingletonBeanRemote MOBILE_PROVIDER_BEAN;
@Override
public MobileProvider getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+ // Is the instance there?
+ if (MOBILE_PROVIDER_BEAN == null) {
+ try {
+ // Not yet, attempt lookup
+ Context initial = new InitialContext();
+
+ // Lookup EJB
+ MOBILE_PROVIDER_BEAN = (MobileProviderSingletonBeanRemote) initial.lookup("java:global/jfinancials-ejb/mobileprovider!org.mxchange.jphone.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote");
+ } catch (final NamingException ex) {
+ // Throw it again
+ throw new ConverterException(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
}
// Get full list
- List<MobileProvider> providerList = this.mobileProviderBean.allMobileProviders();
+ List<MobileProvider> providerList = this.MOBILE_PROVIDER_BEAN.allMobileProviders();
// Init value
MobileProvider provider = null;