]> git.mxchange.org Git - jfinancials-lib.git/commitdiff
try to get through @EJB?
authorRoland Haeder <roland@mxchange.org>
Tue, 13 Oct 2015 11:51:01 +0000 (13:51 +0200)
committerRoland Haeder <roland@mxchange.org>
Tue, 13 Oct 2015 11:51:01 +0000 (13:51 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/addressbook/validator/addressbook/AddressbookIdValidator.java
src/org/mxchange/addressbook/validator/names/AddressbookNameValidator.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
index b9a3b545e27d161e671590a6894bac9f70f90379..1e43b908d0ae63cc80827bde33bce6a953037ea6 100644 (file)
@@ -18,6 +18,7 @@ package org.mxchange.addressbook.validator.names;
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
 import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
 import org.mxchange.jcoreee.validator.string.BaseStringValidator;
@@ -27,6 +28,7 @@ import org.mxchange.jcoreee.validator.string.BaseStringValidator;
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
+@FacesValidator (value = "AddressbookNameValidator")
 public class AddressbookNameValidator extends BaseStringValidator implements Validator {
 
        /**