]> git.mxchange.org Git - jfinancials-lib.git/blobdiff - src/org/mxchange/addressbook/validator/addressbook/AddressbookIdValidator.java
try to get through @EJB?
[jfinancials-lib.git] / src / org / mxchange / addressbook / validator / addressbook / AddressbookIdValidator.java
index c86a8fdfa2064320b0bd6330cb9c5abace479a64..2b97044d6f171b93a53b53ef85cd6502247e51d9 100644 (file)
 package org.mxchange.addressbook.validator.addressbook;
 
 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.faces.view.facelets.FaceletException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote;
 import org.mxchange.jcoreee.validator.number.BaseLongValidator;
 
@@ -45,25 +42,9 @@ public class AddressbookIdValidator extends BaseLongValidator {
        /**
         * Remote bean
         */
+       @EJB (mappedName = "ejb/stateless-addressbook")
        private AddressbookSessionBeanRemote addressbookBean;
 
-       /**
-        * Default constructor
-        */
-       public AddressbookIdValidator () {
-               // Try it
-               try {
-                       // Get context
-                       Context context = new InitialContext();
-
-                       // Try to to lookup the bean
-                       this.addressbookBean = (AddressbookSessionBeanRemote) context.lookup("ejb/stateless-addressbook");
-               } catch (final NamingException ex) {
-                       // Throw again
-                       throw new FaceletException(ex);
-               }
-       }
-
        @Override
        public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
                // Trace message
@@ -78,7 +59,7 @@ public class AddressbookIdValidator extends BaseLongValidator {
                // Is the address book id valid?
                if (!this.addressbookBean.isAddressbookIdUsed((Long) value)) {
                        // Is not valid
-                       throw new ValidatorException(new FacesMessage(MessageFormat.format("No address book found with id {0}. Please check your link.", value)));
+                       throw new ValidatorException(new FacesMessage(MessageFormat.format("No address book found with id {0}. Please check your link.", value))); //NOI18N
                }
 
                // Trace message