From b4200e8ab290b42806d0972ef546e94ec183de49 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Tue, 13 Oct 2015 13:51:01 +0200 Subject: [PATCH] =?utf8?q?try=20to=20get=20through=20@EJB=3F=20Signed-off-?= =?utf8?q?by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../addressbook/AddressbookIdValidator.java | 25 +++---------------- .../names/AddressbookNameValidator.java | 2 ++ 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/src/org/mxchange/addressbook/validator/addressbook/AddressbookIdValidator.java b/src/org/mxchange/addressbook/validator/addressbook/AddressbookIdValidator.java index c86a8fd..2b97044 100644 --- a/src/org/mxchange/addressbook/validator/addressbook/AddressbookIdValidator.java +++ b/src/org/mxchange/addressbook/validator/addressbook/AddressbookIdValidator.java @@ -17,15 +17,12 @@ 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 diff --git a/src/org/mxchange/addressbook/validator/names/AddressbookNameValidator.java b/src/org/mxchange/addressbook/validator/names/AddressbookNameValidator.java index b9a3b54..1e43b90 100644 --- a/src/org/mxchange/addressbook/validator/names/AddressbookNameValidator.java +++ b/src/org/mxchange/addressbook/validator/names/AddressbookNameValidator.java @@ -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; *

* @author Roland Haeder */ +@FacesValidator (value = "AddressbookNameValidator") public class AddressbookNameValidator extends BaseStringValidator implements Validator { /** -- 2.39.5