package org.mxchange.pizzaapplication.validator.user;
import java.text.MessageFormat;
-import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.ValidatorException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
import org.mxchange.jcoreee.validator.number.BaseNumberValidator;
import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
public class PizzaUserIdValidator extends BaseNumberValidator {
/**
- * Serial number
+ * Remote bean
*/
- private static final long serialVersionUID = 12_869_569_314_764_690L;
+ private static UserSessionBeanRemote USER_BEAN;
/**
- * Remote bean
+ * Serial number
*/
- @EJB (lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
- private UserSessionBeanRemote userBean;
+ private static final long serialVersionUID = 12_869_569_314_764_690L;
/**
* Default constructor
@Override
public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // Is the instance there?
+ if (USER_BEAN == null) {
+ try {
+ // Not yet, attempt lookup
+ Context initial = new InitialContext();
+
+ // Lookup EJB
+ USER_BEAN = (UserSessionBeanRemote) initial.lookup("java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote");
+ } catch (final NamingException ex) {
+ // Throw it again
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
+ }
+ }
+
// All accepted, required fields
String[] requiredFields = {"userId"}; //NOI18N
Long userId = (Long) value;
// Define variable
- Boolean ifUserExists = this.userBean.ifUserIdExists(userId);
+ Boolean ifUserExists = USER_BEAN.ifUserIdExists(userId);
// Is the user id valid?
if (!ifUserExists) {