myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Howard W. Smith, Jr." <>
Subject Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...
Date Sun, 14 Apr 2013 00:58:08 GMT
On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <>wrote:

> When i dont want to use codi I use jndi lookup, it is to easy to use and
> portable. I create a simple method for retrive my ejbs without using codi
> instead i use jndi using only the name of the ejb class.
> El 13/04/2013 11:45, "Howard W. Smith, Jr." <>
> escribió:

JNDI works, thank you!  This was the first time I 'ever' had to use JNDI
lookup. I had to research it (search google, look at TomEE examples - ejb
reference[1][2][3], surely did not want to create an 'interface', kept
looking, looked at tomee log, as i know it lists all @EJBs at startup in
the log, didn't see what i was looking for, so i looked at RI/Glassfish
log, since i 'remembered' that RI/Glassfish mentions the JNDI lookup path
for all my @EJB's in the glassfish log at 'startup' of my app)...

So, per an oracle blog[4][5] about JNDI lookup and what i saw in glassfish
log (12/9/2012 was last time i used glassfish to start my, I
modified the @Singleton @Lock(READ) bean, accordingly (see code below),
tested it, and voila, it works!!!! :)

 * To change this template, choose Tools | Templates
 * and open the template in the editor.
package converter;

import java.util.concurrent.TimeUnit;

import javax.ejb.AccessTimeout;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.Singleton;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import javax.naming.InitialContext;

import jpa.entities.Customer;
import jpa.session.CustomerFacade;

@AccessTimeout(value = 1, unit = TimeUnit.MINUTES)
@FacesConverter(forClass = Customer.class)
public class CustomerConverter implements Converter {

    public CustomerConverter() {


    public Object getAsObject(FacesContext facesContext, UIComponent
component, String value) {
        if (value == null || value.length() == 0) {
            return null;
         * 2012-07-10 when user enters invalid/incomplete value (e.g.
"irene", see below) in AutoComplete
        WARNING: For input string: "irene"
        java.lang.NumberFormatException: For input string: "irene"
                at java.lang.Integer.parseInt(
                at java.lang.Integer.valueOf(
                at javax.faces.component.UIInput.validate(
        try {
            Integer test = getKey(value);
        } catch (java.lang.NumberFormatException e) {
            return null;
        Object object = null;
        CustomerFacade ejbFacade;
        try {
            InitialContext ic = new InitialContext();
            ejbFacade = (CustomerFacade)
            if (ejbFacade == null) {
ejbFacade = null)");
                return null;
        } catch (Exception e) {
            System.err.println("CustomerConverter.getAsObject(): error on
JNDI lookup of CustomerFacade");
            return null;
        try {
            object = ejbFacade.find(getKey(value));
        } catch (Exception e) {
            System.err.println("CustomerConverter.getAsObject(): error on
            return null;
        return object;

    java.lang.Integer getKey(String value) {
        java.lang.Integer key;
        key = Integer.valueOf(value);
        return key;

    String getStringKey(java.lang.Integer value) {
        StringBuffer sb = new StringBuffer();
        return sb.toString();

    public String getAsString(FacesContext facesContext, UIComponent
component, Object object) {
        if (object == null) {
            return null;
        if (object instanceof Customer) {
            Customer o = (Customer) object;
            return getStringKey(o.getCustomerId());
        } else {
            throw new IllegalArgumentException("object " + object + " is of
type " + object.getClass().getName() + "; expected type: " +

tomee examples - ejb reference

oracle blogs

which references the following, but needed to replace 'sun' with 'oracle'
in the URL


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message