/*
- * Copyright (C) 2016, 2017 Roland Häder
+ * Copyright (C) 2016 - 2022 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.jfinancials.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.jfinancials.beans.business.opening_time.FinancialsOpeningTimeWebRequestController;
+import org.mxchange.jfinancials.beans.business.opening_time.list.FinancialsOpeningTimeListWebViewBean;
+import org.mxchange.jfinancials.beans.business.opening_time.list.FinancialsOpeningTimeListWebViewController;
/**
* Converter for opening time id <-> instance
/**
* Opening time backing bean
*/
- private static FinancialsOpeningTimeWebRequestController DEPARTMENT_CONTROLLER;
+ private static FinancialsOpeningTimeListWebViewController OPENING_TIME_LIST_CONTROLLER;
@Override
public OpeningTime getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (DEPARTMENT_CONTROLLER == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- DEPARTMENT_CONTROLLER = (FinancialsOpeningTimeWebRequestController) initial.lookup("java:module/openingTimeController!org.mxchange.jfinancials.beans.business.opening_time.FinancialsOpeningTimeWebRequestController"); //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
- // @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
OpeningTime openingTime = null;
+ // Is the instance there?
+ if (null == OPENING_TIME_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ OPENING_TIME_LIST_CONTROLLER = CDI.current().select(FinancialsOpeningTimeListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
- final Long openingId = Long.valueOf(submittedValue);
+ final Long openingTimeId = Long.valueOf(submittedValue);
// Try to get user instance from it
- openingTime = DEPARTMENT_CONTROLLER.findOpeningTimeById(openingId);
+ openingTime = OPENING_TIME_LIST_CONTROLLER.findOpeningTimeById(openingTimeId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
}
// Return id number
- return String.valueOf(value.getOpeningId());
+ return String.valueOf(value.getOpeningTimeId());
}
}