*/
package org.mxchange.addressbook.converter.business.branchoffice;
-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.addressbook.beans.business.branchoffice.list.AddressbookBranchOfficeListWebViewBean;
+import org.mxchange.addressbook.beans.business.branchoffice.list.AddressbookBranchOfficeListWebViewController;
import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeNotFoundException;
import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote;
/**
* Converter for branch office id <-> valid basic company data instance
/**
* Branch office EJB
*/
- private static BranchOfficeSessionBeanRemote BRANCH_OFFICE_BEAN;
+ private static AddressbookBranchOfficeListWebViewController BRANCH_OFFICE_LIST_CONTROLLER;
@Override
public BranchOffice getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (BRANCH_OFFICE_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- BRANCH_OFFICE_BEAN = (BranchOfficeSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote");
- } 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 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;
}
// Init instance
BranchOffice branchOffice = null;
+ // Is the instance there?
+ if (null == BRANCH_OFFICE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ BRANCH_OFFICE_LIST_CONTROLLER = CDI.current().select(AddressbookBranchOfficeListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
- final Long branchOfficeId = Long.valueOf(submittedValue);
+ final Long branchId = Long.valueOf(submittedValue);
// Try to get user instance from it
- branchOffice = BRANCH_OFFICE_BEAN.findBranchOfficeById(branchOfficeId);
+ branchOffice = BRANCH_OFFICE_LIST_CONTROLLER.findBranchOfficeById(branchId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);