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;
/**
* 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
// 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
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;
* <p>
* @author Roland Haeder<roland@mxchange.org>
*/
+@FacesValidator (value = "AddressbookNameValidator")
public class AddressbookNameValidator extends BaseStringValidator implements Validator {
/**