You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Howard W. Smith, Jr." <sm...@gmail.com> on 2013/04/13 13:40:37 UTC

@Singleton @Lock(READ) to resolve, Could not instantiate converter ...

In an effort to remove 'static' declarations throughout my app (to help
JVM's GC), I removed 'static' from the definition of the Converter class
below. So that resulted in the infamous error below:

Apr 13, 2013 4:10:38 AM org.apache.myfaces.application.ApplicationImpl
internalCreateConverter
SEVERE: Could not instantiate converter
jsf.CustomerController$CustomerControllerConverter
java.lang.InstantiationException:
jsf.CustomerController$CustomerControllerConverter
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at
org.apache.myfaces.application.ApplicationImpl.internalCreateConverter(ApplicationImpl.java:1626)
at
org.apache.myfaces.application.ApplicationImpl.createConverter(ApplicationImpl.java:1545)
at
javax.faces.application.ApplicationWrapper.createConverter(ApplicationWrapper.java:158)

I assume 'static' is necessary, because only one copy of the class is
created per application. Correct? So, can I define the class as a
@Singleton @Lock(READ) to resolve the issue?

Per NetBeans generated JSF controller/bean code, the Converter is usually
defined in the same .java file as the controller or @ManagedBean. Honestly,
I do 'not' want to use addConverter() or converterId="..." in the xhtml. I
prefer to use @FacesConverter, since this has been working for me
throughout the app.


    package jsf;

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

    import java.io.Serializable;
    import javax.ejb.EJB;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.RequestScoped;
    import javax.faces.component.UIComponent;
    import javax.faces.context.FacesContext;
    import javax.faces.convert.Converter;
    import javax.faces.convert.FacesConverter;

    @ManagedBean(name = "customerController")
    @RequestScoped
    public class CustomerController implements Serializable {

        @EJB
        private jpa.session.CustomerFacade ejbFacade;

        public CustomerController() {
        }

        @FacesConverter(forClass = Customer.class)
        public class CustomerControllerConverter implements Converter {

            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.NumberFormatException.forInputString(NumberFormatException.java:65)
                        at java.lang.Integer.parseInt(Integer.java:492)
                        at java.lang.Integer.valueOf(Integer.java:582)
                        at
jsf.pointOfContact.pf_PointOfContactController$PointOfContactControllerConverter.getKey(pf_PointOfContactController.java:1625)
                        at
jsf.pointOfContact.pf_PointOfContactController$PointOfContactControllerConverter.getAsObject(pf_PointOfContactController.java:1620)
                        at
org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:529)
                        at
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
                        at
javax.faces.component.UIInput.validate(UIInput.java:960)
                 *
                 */
                try {
                    Integer test = getKey(value);
                } catch (java.lang.NumberFormatException e) {
                    return null;
                }
                CustomerController controller = (CustomerController)
facesContext.getApplication().getELResolver().
                        getValue(facesContext.getELContext(), null,
"customerController");
                return controller.ejbFacade.find(getKey(value));
            }

            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();
                sb.append(value);
                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: " +
Customer.class.getName());
                }
            }
        }
    }


Thanks,
Howard

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by José Luis Cetina <ma...@gmail.com>.
Yes the idea in converters if something is wrong and u wanna display some
info the idea is throw the converterexception.

Please do a request or send mail to tomee mailing list and i can help to
vote.

Regards.
El 13/04/2013 20:51, "Howard W. Smith, Jr." <sm...@gmail.com>
escribió:

> On Sat, Apr 13, 2013 at 9:41 PM, José Luis Cetina <maxtorzito@gmail.com
> >wrote:
>
> > Maybe could be a request for Rommain, i remember that tomee logs some
> info
> > about ejb but im not sure what exactly.
> >
> >
> Agreed, or even better, i'm sure Romain and TomEE committers will
> appreciate me opening a JIRA for it.  :)
>
> Below, is how TomEE logs the @Stateless EJBs. Do you see JNDI lookup path?
> :)
>
> Apr 13, 2013 8:36:09 PM org.apache.openejb.config.InitEjbDeployments deploy
> INFO: Auto-deploying ejb CustomerFacade:
> EjbDeployment(deployment-id=CustomerFacade)
>
>
> By the way i saw that you return null in your converters catch "statement".
> > Why dont throw a converterexception?
> >
>
> Hmmm, good question. Will the JNDI lookup path 'ever' be 'null'? i'm sure
> if I change the name of any of the Stateless @EJBs, then it may return
> 'null'. Right? :)
>
> Okay, I will throw the exception. of course, omnifaces will catch the error
> and display it via error page. :)
>
> Thank you and Mike for your responses and recommendations!!!
>
>
>
> > El 13/04/2013 20:37, "Howard W. Smith, Jr." <sm...@gmail.com>
> > escribió:
> >
> > > It would be nice if TomEE 'logs' the JNDI lookup path as the Reference
> > > Implementation (Glassfish) does! I had to say that. :)
> > >
> > >
> > > On Sat, Apr 13, 2013 at 9:34 PM, José Luis Cetina <
> maxtorzito@gmail.com
> > > >wrote:
> > >
> > > > Congrats. Howard. Just FYI tomee logs the ejb "path" of all yours
> ejbs
> > > > deployed and is not necesary to implement an interface for use jndi.
> > > >
> > > > Good to see that you got a solution.
> > > >
> > > > Regards.
> > > > El 13/04/2013 19:58, "Howard W. Smith, Jr." <sm...@gmail.com>
> > > > escribió:
> > > >
> > > > > On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <
> > > maxtorzito@gmail.com
> > > > > >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." <
> > smithh032772@gmail.com>
> > > > > > escribió:
> > > > > >
> > > > > >
> > > > > José,
> > > > >
> > > > > 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
> > > app...smile), 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;
> > > > >
> > > > >
> > > > > @Singleton
> > > > > @Lock(LockType.READ)
> > > > > @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.NumberFormatException.forInputString(NumberFormatException.java:65)
> > > > >                 at java.lang.Integer.parseInt(Integer.java:492)
> > > > >                 at java.lang.Integer.valueOf(Integer.java:582)
> > > > >                 ...
> > > > >                 ...
> > > > >                 at
> > > > >
> > > > >
> > > >
> > >
> >
> org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:529)
> > > > >                 at
> > > > > javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
> > > > >                 at
> > > > javax.faces.component.UIInput.validate(UIInput.java:960)
> > > > >          *
> > > > >          */
> > > > >         try {
> > > > >             Integer test = getKey(value);
> > > > >         } catch (java.lang.NumberFormatException e) {
> > > > >             return null;
> > > > >         }
> > > > >         Object object = null;
> > > > >         CustomerFacade ejbFacade;
> > > > >         try {
> > > > >             InitialContext ic = new InitialContext();
> > > > >             ejbFacade = (CustomerFacade)
> > > > > ic.lookup("java:global/mcmsweb/CustomerFacade");
> > > > >             if (ejbFacade == null) {
> > > > >
> System.err.println("CustomerConverter.getAsObject():
> > > > > ejbFacade = null)");
> > > > >                 return null;
> > > > >             }
> > > > >         } catch (Exception e) {
> > > > >             System.err.println("CustomerConverter.getAsObject():
> > error
> > > on
> > > > > JNDI lookup of CustomerFacade");
> > > > >             e.printStackTrace();
> > > > >             return null;
> > > > >         }
> > > > >         try {
> > > > >             object = ejbFacade.find(getKey(value));
> > > > >         } catch (Exception e) {
> > > > >             System.err.println("CustomerConverter.getAsObject():
> > error
> > > on
> > > > > ejbFacade.find(getKey(value))");
> > > > >             e.printStackTrace();
> > > > >             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();
> > > > >         sb.append(value);
> > > > >         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: " +
> > > > > Customer.class.getName());
> > > > >         }
> > > > >     }
> > > > > }
> > > > >
> > > > >
> > > > > tomee examples - ejb reference
> > > > > [1]
> > > http://tomee.apache.org/examples-trunk/injection-of-ejbs/README.html
> > > > > [2]
> > > > >
> > > > >
> > > >
> > >
> >
> http://tomee.apache.org/examples-trunk/lookup-of-ejbs-with-descriptor/README.html
> > > > > [3]
> > http://tomee.apache.org/examples-trunk/lookup-of-ejbs/README.html
> > > > >
> > > > > oracle blogs
> > > > > [4]
> > > > >
> > > > >
> > > >
> > >
> >
> https://blogs.oracle.com/kensaks/entry/application_specified_portable_jndi_names
> > > > >
> > > > > which references the following, but needed to replace 'sun' with
> > > 'oracle'
> > > > > in the URL
> > > > >
> > > > > [5]
> > https://blogs.oracle.com/kensaks/entry/portable_global_jndi_names
> > > > >
> > > >
> > >
> >
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
On Sat, Apr 13, 2013 at 9:41 PM, José Luis Cetina <ma...@gmail.com>wrote:

> Maybe could be a request for Rommain, i remember that tomee logs some info
> about ejb but im not sure what exactly.
>
>
Agreed, or even better, i'm sure Romain and TomEE committers will
appreciate me opening a JIRA for it.  :)

Below, is how TomEE logs the @Stateless EJBs. Do you see JNDI lookup path?
:)

Apr 13, 2013 8:36:09 PM org.apache.openejb.config.InitEjbDeployments deploy
INFO: Auto-deploying ejb CustomerFacade:
EjbDeployment(deployment-id=CustomerFacade)


By the way i saw that you return null in your converters catch "statement".
> Why dont throw a converterexception?
>

Hmmm, good question. Will the JNDI lookup path 'ever' be 'null'? i'm sure
if I change the name of any of the Stateless @EJBs, then it may return
'null'. Right? :)

Okay, I will throw the exception. of course, omnifaces will catch the error
and display it via error page. :)

Thank you and Mike for your responses and recommendations!!!



> El 13/04/2013 20:37, "Howard W. Smith, Jr." <sm...@gmail.com>
> escribió:
>
> > It would be nice if TomEE 'logs' the JNDI lookup path as the Reference
> > Implementation (Glassfish) does! I had to say that. :)
> >
> >
> > On Sat, Apr 13, 2013 at 9:34 PM, José Luis Cetina <maxtorzito@gmail.com
> > >wrote:
> >
> > > Congrats. Howard. Just FYI tomee logs the ejb "path" of all yours ejbs
> > > deployed and is not necesary to implement an interface for use jndi.
> > >
> > > Good to see that you got a solution.
> > >
> > > Regards.
> > > El 13/04/2013 19:58, "Howard W. Smith, Jr." <sm...@gmail.com>
> > > escribió:
> > >
> > > > On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <
> > maxtorzito@gmail.com
> > > > >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." <
> smithh032772@gmail.com>
> > > > > escribió:
> > > > >
> > > > >
> > > > José,
> > > >
> > > > 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
> > app...smile), 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;
> > > >
> > > >
> > > > @Singleton
> > > > @Lock(LockType.READ)
> > > > @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.NumberFormatException.forInputString(NumberFormatException.java:65)
> > > >                 at java.lang.Integer.parseInt(Integer.java:492)
> > > >                 at java.lang.Integer.valueOf(Integer.java:582)
> > > >                 ...
> > > >                 ...
> > > >                 at
> > > >
> > > >
> > >
> >
> org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:529)
> > > >                 at
> > > > javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
> > > >                 at
> > > javax.faces.component.UIInput.validate(UIInput.java:960)
> > > >          *
> > > >          */
> > > >         try {
> > > >             Integer test = getKey(value);
> > > >         } catch (java.lang.NumberFormatException e) {
> > > >             return null;
> > > >         }
> > > >         Object object = null;
> > > >         CustomerFacade ejbFacade;
> > > >         try {
> > > >             InitialContext ic = new InitialContext();
> > > >             ejbFacade = (CustomerFacade)
> > > > ic.lookup("java:global/mcmsweb/CustomerFacade");
> > > >             if (ejbFacade == null) {
> > > >                 System.err.println("CustomerConverter.getAsObject():
> > > > ejbFacade = null)");
> > > >                 return null;
> > > >             }
> > > >         } catch (Exception e) {
> > > >             System.err.println("CustomerConverter.getAsObject():
> error
> > on
> > > > JNDI lookup of CustomerFacade");
> > > >             e.printStackTrace();
> > > >             return null;
> > > >         }
> > > >         try {
> > > >             object = ejbFacade.find(getKey(value));
> > > >         } catch (Exception e) {
> > > >             System.err.println("CustomerConverter.getAsObject():
> error
> > on
> > > > ejbFacade.find(getKey(value))");
> > > >             e.printStackTrace();
> > > >             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();
> > > >         sb.append(value);
> > > >         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: " +
> > > > Customer.class.getName());
> > > >         }
> > > >     }
> > > > }
> > > >
> > > >
> > > > tomee examples - ejb reference
> > > > [1]
> > http://tomee.apache.org/examples-trunk/injection-of-ejbs/README.html
> > > > [2]
> > > >
> > > >
> > >
> >
> http://tomee.apache.org/examples-trunk/lookup-of-ejbs-with-descriptor/README.html
> > > > [3]
> http://tomee.apache.org/examples-trunk/lookup-of-ejbs/README.html
> > > >
> > > > oracle blogs
> > > > [4]
> > > >
> > > >
> > >
> >
> https://blogs.oracle.com/kensaks/entry/application_specified_portable_jndi_names
> > > >
> > > > which references the following, but needed to replace 'sun' with
> > 'oracle'
> > > > in the URL
> > > >
> > > > [5]
> https://blogs.oracle.com/kensaks/entry/portable_global_jndi_names
> > > >
> > >
> >
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by José Luis Cetina <ma...@gmail.com>.
Maybe could be a request for Rommain, i remember that tomee logs some info
about ejb but im not sure what exactly.

By the way i saw that you return null in your converters catch "statement".
Why dont throw a converterexception?
El 13/04/2013 20:37, "Howard W. Smith, Jr." <sm...@gmail.com>
escribió:

> It would be nice if TomEE 'logs' the JNDI lookup path as the Reference
> Implementation (Glassfish) does! I had to say that. :)
>
>
> On Sat, Apr 13, 2013 at 9:34 PM, José Luis Cetina <maxtorzito@gmail.com
> >wrote:
>
> > Congrats. Howard. Just FYI tomee logs the ejb "path" of all yours ejbs
> > deployed and is not necesary to implement an interface for use jndi.
> >
> > Good to see that you got a solution.
> >
> > Regards.
> > El 13/04/2013 19:58, "Howard W. Smith, Jr." <sm...@gmail.com>
> > escribió:
> >
> > > On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <
> maxtorzito@gmail.com
> > > >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." <sm...@gmail.com>
> > > > escribió:
> > > >
> > > >
> > > José,
> > >
> > > 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
> app...smile), 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;
> > >
> > >
> > > @Singleton
> > > @Lock(LockType.READ)
> > > @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.NumberFormatException.forInputString(NumberFormatException.java:65)
> > >                 at java.lang.Integer.parseInt(Integer.java:492)
> > >                 at java.lang.Integer.valueOf(Integer.java:582)
> > >                 ...
> > >                 ...
> > >                 at
> > >
> > >
> >
> org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:529)
> > >                 at
> > > javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
> > >                 at
> > javax.faces.component.UIInput.validate(UIInput.java:960)
> > >          *
> > >          */
> > >         try {
> > >             Integer test = getKey(value);
> > >         } catch (java.lang.NumberFormatException e) {
> > >             return null;
> > >         }
> > >         Object object = null;
> > >         CustomerFacade ejbFacade;
> > >         try {
> > >             InitialContext ic = new InitialContext();
> > >             ejbFacade = (CustomerFacade)
> > > ic.lookup("java:global/mcmsweb/CustomerFacade");
> > >             if (ejbFacade == null) {
> > >                 System.err.println("CustomerConverter.getAsObject():
> > > ejbFacade = null)");
> > >                 return null;
> > >             }
> > >         } catch (Exception e) {
> > >             System.err.println("CustomerConverter.getAsObject(): error
> on
> > > JNDI lookup of CustomerFacade");
> > >             e.printStackTrace();
> > >             return null;
> > >         }
> > >         try {
> > >             object = ejbFacade.find(getKey(value));
> > >         } catch (Exception e) {
> > >             System.err.println("CustomerConverter.getAsObject(): error
> on
> > > ejbFacade.find(getKey(value))");
> > >             e.printStackTrace();
> > >             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();
> > >         sb.append(value);
> > >         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: " +
> > > Customer.class.getName());
> > >         }
> > >     }
> > > }
> > >
> > >
> > > tomee examples - ejb reference
> > > [1]
> http://tomee.apache.org/examples-trunk/injection-of-ejbs/README.html
> > > [2]
> > >
> > >
> >
> http://tomee.apache.org/examples-trunk/lookup-of-ejbs-with-descriptor/README.html
> > > [3] http://tomee.apache.org/examples-trunk/lookup-of-ejbs/README.html
> > >
> > > oracle blogs
> > > [4]
> > >
> > >
> >
> https://blogs.oracle.com/kensaks/entry/application_specified_portable_jndi_names
> > >
> > > which references the following, but needed to replace 'sun' with
> 'oracle'
> > > in the URL
> > >
> > > [5] https://blogs.oracle.com/kensaks/entry/portable_global_jndi_names
> > >
> >
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
It would be nice if TomEE 'logs' the JNDI lookup path as the Reference
Implementation (Glassfish) does! I had to say that. :)


On Sat, Apr 13, 2013 at 9:34 PM, José Luis Cetina <ma...@gmail.com>wrote:

> Congrats. Howard. Just FYI tomee logs the ejb "path" of all yours ejbs
> deployed and is not necesary to implement an interface for use jndi.
>
> Good to see that you got a solution.
>
> Regards.
> El 13/04/2013 19:58, "Howard W. Smith, Jr." <sm...@gmail.com>
> escribió:
>
> > On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <maxtorzito@gmail.com
> > >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." <sm...@gmail.com>
> > > escribió:
> > >
> > >
> > José,
> >
> > 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 app...smile), 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;
> >
> >
> > @Singleton
> > @Lock(LockType.READ)
> > @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.NumberFormatException.forInputString(NumberFormatException.java:65)
> >                 at java.lang.Integer.parseInt(Integer.java:492)
> >                 at java.lang.Integer.valueOf(Integer.java:582)
> >                 ...
> >                 ...
> >                 at
> >
> >
> org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:529)
> >                 at
> > javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
> >                 at
> javax.faces.component.UIInput.validate(UIInput.java:960)
> >          *
> >          */
> >         try {
> >             Integer test = getKey(value);
> >         } catch (java.lang.NumberFormatException e) {
> >             return null;
> >         }
> >         Object object = null;
> >         CustomerFacade ejbFacade;
> >         try {
> >             InitialContext ic = new InitialContext();
> >             ejbFacade = (CustomerFacade)
> > ic.lookup("java:global/mcmsweb/CustomerFacade");
> >             if (ejbFacade == null) {
> >                 System.err.println("CustomerConverter.getAsObject():
> > ejbFacade = null)");
> >                 return null;
> >             }
> >         } catch (Exception e) {
> >             System.err.println("CustomerConverter.getAsObject(): error on
> > JNDI lookup of CustomerFacade");
> >             e.printStackTrace();
> >             return null;
> >         }
> >         try {
> >             object = ejbFacade.find(getKey(value));
> >         } catch (Exception e) {
> >             System.err.println("CustomerConverter.getAsObject(): error on
> > ejbFacade.find(getKey(value))");
> >             e.printStackTrace();
> >             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();
> >         sb.append(value);
> >         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: " +
> > Customer.class.getName());
> >         }
> >     }
> > }
> >
> >
> > tomee examples - ejb reference
> > [1] http://tomee.apache.org/examples-trunk/injection-of-ejbs/README.html
> > [2]
> >
> >
> http://tomee.apache.org/examples-trunk/lookup-of-ejbs-with-descriptor/README.html
> > [3] http://tomee.apache.org/examples-trunk/lookup-of-ejbs/README.html
> >
> > oracle blogs
> > [4]
> >
> >
> https://blogs.oracle.com/kensaks/entry/application_specified_portable_jndi_names
> >
> > which references the following, but needed to replace 'sun' with 'oracle'
> > in the URL
> >
> > [5] https://blogs.oracle.com/kensaks/entry/portable_global_jndi_names
> >
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by José Luis Cetina <ma...@gmail.com>.
Congrats. Howard. Just FYI tomee logs the ejb "path" of all yours ejbs
deployed and is not necesary to implement an interface for use jndi.

Good to see that you got a solution.

Regards.
El 13/04/2013 19:58, "Howard W. Smith, Jr." <sm...@gmail.com>
escribió:

> On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <maxtorzito@gmail.com
> >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." <sm...@gmail.com>
> > escribió:
> >
> >
> José,
>
> 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 app...smile), 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;
>
>
> @Singleton
> @Lock(LockType.READ)
> @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.NumberFormatException.forInputString(NumberFormatException.java:65)
>                 at java.lang.Integer.parseInt(Integer.java:492)
>                 at java.lang.Integer.valueOf(Integer.java:582)
>                 ...
>                 ...
>                 at
>
> org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:529)
>                 at
> javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
>                 at javax.faces.component.UIInput.validate(UIInput.java:960)
>          *
>          */
>         try {
>             Integer test = getKey(value);
>         } catch (java.lang.NumberFormatException e) {
>             return null;
>         }
>         Object object = null;
>         CustomerFacade ejbFacade;
>         try {
>             InitialContext ic = new InitialContext();
>             ejbFacade = (CustomerFacade)
> ic.lookup("java:global/mcmsweb/CustomerFacade");
>             if (ejbFacade == null) {
>                 System.err.println("CustomerConverter.getAsObject():
> ejbFacade = null)");
>                 return null;
>             }
>         } catch (Exception e) {
>             System.err.println("CustomerConverter.getAsObject(): error on
> JNDI lookup of CustomerFacade");
>             e.printStackTrace();
>             return null;
>         }
>         try {
>             object = ejbFacade.find(getKey(value));
>         } catch (Exception e) {
>             System.err.println("CustomerConverter.getAsObject(): error on
> ejbFacade.find(getKey(value))");
>             e.printStackTrace();
>             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();
>         sb.append(value);
>         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: " +
> Customer.class.getName());
>         }
>     }
> }
>
>
> tomee examples - ejb reference
> [1] http://tomee.apache.org/examples-trunk/injection-of-ejbs/README.html
> [2]
>
> http://tomee.apache.org/examples-trunk/lookup-of-ejbs-with-descriptor/README.html
> [3] http://tomee.apache.org/examples-trunk/lookup-of-ejbs/README.html
>
> oracle blogs
> [4]
>
> https://blogs.oracle.com/kensaks/entry/application_specified_portable_jndi_names
>
> which references the following, but needed to replace 'sun' with 'oracle'
> in the URL
>
> [5] https://blogs.oracle.com/kensaks/entry/portable_global_jndi_names
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <ma...@gmail.com>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." <sm...@gmail.com>
> escribió:
>
>
José,

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 app...smile), 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;


@Singleton
@Lock(LockType.READ)
@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.NumberFormatException.forInputString(NumberFormatException.java:65)
                at java.lang.Integer.parseInt(Integer.java:492)
                at java.lang.Integer.valueOf(Integer.java:582)
                ...
                ...
                at
org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:529)
                at
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
                at javax.faces.component.UIInput.validate(UIInput.java:960)
         *
         */
        try {
            Integer test = getKey(value);
        } catch (java.lang.NumberFormatException e) {
            return null;
        }
        Object object = null;
        CustomerFacade ejbFacade;
        try {
            InitialContext ic = new InitialContext();
            ejbFacade = (CustomerFacade)
ic.lookup("java:global/mcmsweb/CustomerFacade");
            if (ejbFacade == null) {
                System.err.println("CustomerConverter.getAsObject():
ejbFacade = null)");
                return null;
            }
        } catch (Exception e) {
            System.err.println("CustomerConverter.getAsObject(): error on
JNDI lookup of CustomerFacade");
            e.printStackTrace();
            return null;
        }
        try {
            object = ejbFacade.find(getKey(value));
        } catch (Exception e) {
            System.err.println("CustomerConverter.getAsObject(): error on
ejbFacade.find(getKey(value))");
            e.printStackTrace();
            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();
        sb.append(value);
        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: " +
Customer.class.getName());
        }
    }
}


tomee examples - ejb reference
[1] http://tomee.apache.org/examples-trunk/injection-of-ejbs/README.html
[2]
http://tomee.apache.org/examples-trunk/lookup-of-ejbs-with-descriptor/README.html
[3] http://tomee.apache.org/examples-trunk/lookup-of-ejbs/README.html

oracle blogs
[4]
https://blogs.oracle.com/kensaks/entry/application_specified_portable_jndi_names

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

[5] https://blogs.oracle.com/kensaks/entry/portable_global_jndi_names

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Mike, I tried to use this approach, but that approach does 'not' give me
reference to either of the following:

1. CDI @SessionScoped bean (which references the Stateless @EJB via @EJB
annotation)

2. Stateless @EJB

but there is hope, as Jose recommended/advised. See my next response to
Jose's last response.


On Sat, Apr 13, 2013 at 2:05 PM, Mike Kienenberger <mk...@gmail.com>wrote:

> Yes, that's how I linked my database layer to my converters in JSF 1.x
> -- using the Java
> API to pull the database beans out of the JSF context.
>
> On Sat, Apr 13, 2013 at 1:04 PM, Howard W. Smith, Jr.
> <sm...@gmail.com> wrote:
> > On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <maxtorzito@gmail.com
> >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.
> >>
> >
> > Recently, I added the following after listening in on that other/earlier
> > topic/thread on myfaces or openejb list. The code below allowed me to
> > remove CODI dependency. :)
> >
> >     /*
> >      *
> >
> http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html
> >      *
> http://struberg.wordpress.com/2012/03/20/why-is-openwebbeans-so-fast/
> >      */
> >     @SuppressWarnings("unchecked")
> >     public <T> T getBean(Class<T> type) {
> >         Bean<T> bean = (Bean<T>)
> > beanManager.resolve(beanManager.getBeans(type));
> >         CreationalContext<T>  creationalContext =
> >                               beanManager.createCreationalContext(bean);
> >
> >         return (T) beanManager.getReference(bean, type,
> creationalContext);
> >     }
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by Mike Kienenberger <mk...@gmail.com>.
Yes, that's how I linked my database layer to my converters in JSF 1.x
-- using the Java
API to pull the database beans out of the JSF context.

On Sat, Apr 13, 2013 at 1:04 PM, Howard W. Smith, Jr.
<sm...@gmail.com> wrote:
> On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <ma...@gmail.com>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.
>>
>
> Recently, I added the following after listening in on that other/earlier
> topic/thread on myfaces or openejb list. The code below allowed me to
> remove CODI dependency. :)
>
>     /*
>      *
> http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html
>      * http://struberg.wordpress.com/2012/03/20/why-is-openwebbeans-so-fast/
>      */
>     @SuppressWarnings("unchecked")
>     public <T> T getBean(Class<T> type) {
>         Bean<T> bean = (Bean<T>)
> beanManager.resolve(beanManager.getBeans(type));
>         CreationalContext<T>  creationalContext =
>                               beanManager.createCreationalContext(bean);
>
>         return (T) beanManager.getReference(bean, type, creationalContext);
>     }

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
On Sat, Apr 13, 2013 at 1:00 PM, José Luis Cetina <ma...@gmail.com>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.
>

Recently, I added the following after listening in on that other/earlier
topic/thread on myfaces or openejb list. The code below allowed me to
remove CODI dependency. :)

    /*
     *
http://docs.oracle.com/javaee/6/api/javax/enterprise/inject/spi/BeanManager.html
     * http://struberg.wordpress.com/2012/03/20/why-is-openwebbeans-so-fast/
     */
    @SuppressWarnings("unchecked")
    public <T> T getBean(Class<T> type) {
        Bean<T> bean = (Bean<T>)
beanManager.resolve(beanManager.getBeans(type));
        CreationalContext<T>  creationalContext =
                              beanManager.createCreationalContext(bean);

        return (T) beanManager.getReference(bean, type, creationalContext);
    }

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by José Luis Cetina <ma...@gmail.com>.
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." <sm...@gmail.com>
escribió:

> On Sat, Apr 13, 2013 at 12:16 PM, José Luis Cetina <maxtorzito@gmail.com
> >wrote:
>
> >
> > 2. The way i use the converter are in separeted classes and in each
> > converter if i need an ejb injected (limitation of jsf 2.1 this is
> "fixed"
> > in jsf 2.2 ) i use Apache CODI for get the reference of my ejb or i do a
> > lookup using jndi. Using like this way all my converters are classes
> > annotated with facesconverter that i can reuse in any jsf page using the
> > converter tag or if the component provide a converter attribute i use the
> > name of the facesconverter and with this i dont have create an instance
> of
> > the converter in any managedbean, my app have more than 40 converters in
> > this way without any problem . IMO i dont see why you want to use static
> > converter.
> >
>
> Trust me, i do 'not' want to use 'static', but it works-as-designed, right
> now. Your response/implementation is interesting. I thought that Apache
> CODI may be able to resolve this issue, but I recently removed Apache CODI
> from my project, as I didn't need it anymore, since someone else initiated
> a thread/topic about using bean manager instead of Apache CODI's bean
> manager. I'm wonder if I can use the container's bean manager instead of
> Apache CODI bean manager. I will try to implement as you mentioned above.
> Thanks Jose.
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
On Sat, Apr 13, 2013 at 12:16 PM, José Luis Cetina <ma...@gmail.com>wrote:

>
> 2. The way i use the converter are in separeted classes and in each
> converter if i need an ejb injected (limitation of jsf 2.1 this is "fixed"
> in jsf 2.2 ) i use Apache CODI for get the reference of my ejb or i do a
> lookup using jndi. Using like this way all my converters are classes
> annotated with facesconverter that i can reuse in any jsf page using the
> converter tag or if the component provide a converter attribute i use the
> name of the facesconverter and with this i dont have create an instance of
> the converter in any managedbean, my app have more than 40 converters in
> this way without any problem . IMO i dont see why you want to use static
> converter.
>

Trust me, i do 'not' want to use 'static', but it works-as-designed, right
now. Your response/implementation is interesting. I thought that Apache
CODI may be able to resolve this issue, but I recently removed Apache CODI
from my project, as I didn't need it anymore, since someone else initiated
a thread/topic about using bean manager instead of Apache CODI's bean
manager. I'm wonder if I can use the container's bean manager instead of
Apache CODI bean manager. I will try to implement as you mentioned above.
Thanks Jose.

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by José Luis Cetina <ma...@gmail.com>.
1. About the autocomplete the "problem" that i had is that i was getting
the string value typed by the user in the converter and i was expecting to
be the id that i returned in the getasstring method of course i got an
numberformat exception because the string it wasnt the id instead it was
the string typed by the user.  But the problem was because i didnt specify
the event attritube in p:ajax after look this i just add the itemSelect
event and with this i didnt get the the string typed value in the converter
and the exception gone. As i can see, you specify the event in the ajax
tag.

2. The way i use the converter are in separeted classes and in each
converter if i need an ejb injected (limitation of jsf 2.1 this is "fixed"
in jsf 2.2 ) i use Apache CODI for get the reference of my ejb or i do a
lookup using jndi. Using like this way all my converters are classes
annotated with facesconverter that i can reuse in any jsf page using the
converter tag or if the component provide a converter attribute i use the
name of the facesconverter and with this i dont have create an instance of
the converter in any managedbean, my app have more than 40 converters in
this way without any problem . IMO i dont see why you want to use static
converter.
El 13/04/2013 10:41, "Howard W. Smith, Jr." <sm...@gmail.com>
escribió:

> I asked the question and answered on stackoverflow.com[1]. Conclusion, I
> decided to leave the converters defined as static and as members of the
> controller classes, since my preference is to use @FacesConverter(forClass
> = Customer.class).
>
> [1]
>
> http://stackoverflow.com/questions/15987483/singleton-lockread-to-resolve-could-not-instantiate-converter
>
>
> On Sat, Apr 13, 2013 at 10:17 AM, Howard W. Smith, Jr. <
> smithh032772@gmail.com> wrote:
>
> >
> > On Sat, Apr 13, 2013 at 9:58 AM, José Luis Cetina <maxtorzito@gmail.com
> >wrote:
> >
> >> Howard i see you have this problem using the converter with primefaces
> >> autocomplete, just for curiosity do you have a p:ajax inside of the
> >> component? If so can you paste your p:ajax tag? I comment this because i
> >> had the same problem like you but i didnt use static in my converter.
> >>
> >
> > Jose, you're right, I do get this exception when using Autocomplete with
> > p:ajax, but I also see the exception on p:inputText (for Phone #) with no
> > p:ajax, and use Save button to update/save Phone # inputText. :)
> >
> > Below, is the entire xhtml of the autocomplete component for customer.
> >
> > <p:autoComplete id="customerId"
> > value="#{pf_ordersController.selectedCustomer}"
> >                 completeMethod="#{pf_customerController.complete}"
> var="c"
> >                 itemLabel="#{c.customerName}" itemValue="#{c}"
> >                 maxResults="10" queryDelay="300" size="50"
> > onblur="close()">
> >     <p:ajax partialSubmit="false" event="itemSelect"
> >             onstart="bui.block();" oncomplete="bui.unblock();"
> >             update="@(.ui-panel) :orderEditForm:formMessages
> > :orderEditForm:_ajax_status"/>
> >     <f:facet name="itemtip">
> >         <h:panelGrid  columns="2" cellpadding="3">
> >             <f:facet name="header">
> >                 <h:outputText value="#{c.customerName}" />
> >             </f:facet>
> >             <h:outputText value="Number:" />
> >             <h:outputText value="#{c.customerId}" />
> >
> >             <h:outputText value="Leader:" />
> >             <h:outputText value="#{c.leaderPointOfContactId ne null ?
> > c.leaderPointOfContactId.pointOfContactName : ''}"/>
> >         </h:panelGrid>
> >     </f:facet>
> > </p:autoComplete>
> >
> >
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
I asked the question and answered on stackoverflow.com[1]. Conclusion, I
decided to leave the converters defined as static and as members of the
controller classes, since my preference is to use @FacesConverter(forClass
= Customer.class).

[1]
http://stackoverflow.com/questions/15987483/singleton-lockread-to-resolve-could-not-instantiate-converter


On Sat, Apr 13, 2013 at 10:17 AM, Howard W. Smith, Jr. <
smithh032772@gmail.com> wrote:

>
> On Sat, Apr 13, 2013 at 9:58 AM, José Luis Cetina <ma...@gmail.com>wrote:
>
>> Howard i see you have this problem using the converter with primefaces
>> autocomplete, just for curiosity do you have a p:ajax inside of the
>> component? If so can you paste your p:ajax tag? I comment this because i
>> had the same problem like you but i didnt use static in my converter.
>>
>
> Jose, you're right, I do get this exception when using Autocomplete with
> p:ajax, but I also see the exception on p:inputText (for Phone #) with no
> p:ajax, and use Save button to update/save Phone # inputText. :)
>
> Below, is the entire xhtml of the autocomplete component for customer.
>
> <p:autoComplete id="customerId"
> value="#{pf_ordersController.selectedCustomer}"
>                 completeMethod="#{pf_customerController.complete}" var="c"
>                 itemLabel="#{c.customerName}" itemValue="#{c}"
>                 maxResults="10" queryDelay="300" size="50"
> onblur="close()">
>     <p:ajax partialSubmit="false" event="itemSelect"
>             onstart="bui.block();" oncomplete="bui.unblock();"
>             update="@(.ui-panel) :orderEditForm:formMessages
> :orderEditForm:_ajax_status"/>
>     <f:facet name="itemtip">
>         <h:panelGrid  columns="2" cellpadding="3">
>             <f:facet name="header">
>                 <h:outputText value="#{c.customerName}" />
>             </f:facet>
>             <h:outputText value="Number:" />
>             <h:outputText value="#{c.customerId}" />
>
>             <h:outputText value="Leader:" />
>             <h:outputText value="#{c.leaderPointOfContactId ne null ?
> c.leaderPointOfContactId.pointOfContactName : ''}"/>
>         </h:panelGrid>
>     </f:facet>
> </p:autoComplete>
>
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
On Sat, Apr 13, 2013 at 9:58 AM, José Luis Cetina <ma...@gmail.com>wrote:

> Howard i see you have this problem using the converter with primefaces
> autocomplete, just for curiosity do you have a p:ajax inside of the
> component? If so can you paste your p:ajax tag? I comment this because i
> had the same problem like you but i didnt use static in my converter.
>

Jose, you're right, I do get this exception when using Autocomplete with
p:ajax, but I also see the exception on p:inputText (for Phone #) with no
p:ajax, and use Save button to update/save Phone # inputText. :)

Below, is the entire xhtml of the autocomplete component for customer.

<p:autoComplete id="customerId"
value="#{pf_ordersController.selectedCustomer}"
                completeMethod="#{pf_customerController.complete}" var="c"
                itemLabel="#{c.customerName}" itemValue="#{c}"
                maxResults="10" queryDelay="300" size="50" onblur="close()">
    <p:ajax partialSubmit="false" event="itemSelect"
            onstart="bui.block();" oncomplete="bui.unblock();"
            update="@(.ui-panel) :orderEditForm:formMessages
:orderEditForm:_ajax_status"/>
    <f:facet name="itemtip">
        <h:panelGrid  columns="2" cellpadding="3">
            <f:facet name="header">
                <h:outputText value="#{c.customerName}" />
            </f:facet>
            <h:outputText value="Number:" />
            <h:outputText value="#{c.customerId}" />

            <h:outputText value="Leader:" />
            <h:outputText value="#{c.leaderPointOfContactId ne null ?
c.leaderPointOfContactId.pointOfContactName : ''}"/>
        </h:panelGrid>
    </f:facet>
</p:autoComplete>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by José Luis Cetina <ma...@gmail.com>.
Howard i see you have this problem using the converter with primefaces
autocomplete, just for curiosity do you have a p:ajax inside of the
component? If so can you paste your p:ajax tag? I comment this because i
had the same problem like you but i didnt use static in my converter.
El 13/04/2013 08:47, "Howard W. Smith, Jr." <sm...@gmail.com>
escribió:

> Mike,
>
> On Sat, Apr 13, 2013 at 8:38 AM, Mike Kienenberger <mkienenb@gmail.com
> >wrote:
>
> >
> > Maybe your problem is that you are missing the no-arg constructor for
> > the converter.
> > Maybe that was why it worked when it was static.
> >
>
> Interesting. I'm definitely still novice to java, especially use of
> 'static', even though i used it, primarily, for adding static strings
> throughout the app. All along, I knew that 'static' means that only one
> copy will be created/instantiated within/for the parent class.
>
> I think the static reference was added (by Netbeans, when it generated the
> code for me, back in 2011), because of the following:
>
> Below, you will see that the managed bean has a reference to a stateless
> @EJB (DAO),
>
> @ManagedBean(name = "customerController")
> @RequestScoped
> public class CustomerController implements Serializable {
>
>     @EJB
>     private jpa.session.CustomerFacade ejbFacade;
>
> and, the CustomerControllerConverter.getAsObject() method references the
> @EJB which is a member of the managed bean, CustomerController. See below.
>
>             CustomerController controller = (CustomerController)
> facesContext.getApplication().getELResolver().
>                     getValue(facesContext.getELContext(), null,
> "customerController");
>             return controller.ejbFacade.find(getKey(value));
>
>
>
>
> >
> > Was there additional information in java.lang.InstantiationException,
> > like a root cause?
> >
> > I'll have to take a look at that, but I see MyFaces ApplicationImpl which
> throws the exception, but haven't made my way to looking at
> java.lang.InstantiationException, just yet.
>
>
> >
> > The two things I would try are
> > 1)  move it to a separate class
> > 2) add a no-arg constructor
> >
> >
> Will try this and let you know. I think it still may be necessary to add
> the class as a 'public static' class, so there will be only one instance of
> @FacesConverter(forClass = Customer.class) during runtime.
>
>
> > I haven't really written many converters since the annotation support
> > was added, but this is what one of the few I did write looks like.
> > This was a quick proof of concept thing, so I didn't take the time to
> > debug why @FacesConverter(forClass = ) wasn't working for me but
> > instead manually specified a converter id in the one place I used the
> > converter.
> >
>
> Yeah, I really prefer not to use converter id, or I would have to go all
> throughout my xhtml and update, accordingly. Thanks.
>
> Will share any/all updates, ASAP. Thanks Mike!
>

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by "Howard W. Smith, Jr." <sm...@gmail.com>.
Mike,

On Sat, Apr 13, 2013 at 8:38 AM, Mike Kienenberger <mk...@gmail.com>wrote:

>
> Maybe your problem is that you are missing the no-arg constructor for
> the converter.
> Maybe that was why it worked when it was static.
>

Interesting. I'm definitely still novice to java, especially use of
'static', even though i used it, primarily, for adding static strings
throughout the app. All along, I knew that 'static' means that only one
copy will be created/instantiated within/for the parent class.

I think the static reference was added (by Netbeans, when it generated the
code for me, back in 2011), because of the following:

Below, you will see that the managed bean has a reference to a stateless
@EJB (DAO),

@ManagedBean(name = "customerController")
@RequestScoped
public class CustomerController implements Serializable {

    @EJB
    private jpa.session.CustomerFacade ejbFacade;

and, the CustomerControllerConverter.getAsObject() method references the
@EJB which is a member of the managed bean, CustomerController. See below.

            CustomerController controller = (CustomerController)
facesContext.getApplication().getELResolver().
                    getValue(facesContext.getELContext(), null,
"customerController");
            return controller.ejbFacade.find(getKey(value));




>
> Was there additional information in java.lang.InstantiationException,
> like a root cause?
>
> I'll have to take a look at that, but I see MyFaces ApplicationImpl which
throws the exception, but haven't made my way to looking at
java.lang.InstantiationException, just yet.


>
> The two things I would try are
> 1)  move it to a separate class
> 2) add a no-arg constructor
>
>
Will try this and let you know. I think it still may be necessary to add
the class as a 'public static' class, so there will be only one instance of
@FacesConverter(forClass = Customer.class) during runtime.


> I haven't really written many converters since the annotation support
> was added, but this is what one of the few I did write looks like.
> This was a quick proof of concept thing, so I didn't take the time to
> debug why @FacesConverter(forClass = ) wasn't working for me but
> instead manually specified a converter id in the one place I used the
> converter.
>

Yeah, I really prefer not to use converter id, or I would have to go all
throughout my xhtml and update, accordingly. Thanks.

Will share any/all updates, ASAP. Thanks Mike!

Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ...

Posted by Mike Kienenberger <mk...@gmail.com>.
My converters are in separate classes, and I have never declared a
converter static.

Maybe your problem is that you are missing the no-arg constructor for
the converter.
Maybe that was why it worked when it was static.

Was there additional information in java.lang.InstantiationException,
like a root cause?


The two things I would try are
1)  move it to a separate class
2) add a no-arg constructor


I haven't really written many converters since the annotation support
was added, but this is what one of the few I did write looks like.
This was a quick proof of concept thing, so I didn't take the time to
debug why @FacesConverter(forClass = ) wasn't working for me but
instead manually specified a converter id in the one place I used the
converter.


package org.gamenet.conferencePlanner.data.converter;

@FacesConverter("org.gamenet.conferencePlanner.data.converter.SessionConverter")
public class SessionConverter implements Converter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent
component, String key) {
[...]
        }

    }

    @Override
    public String getAsString(FacesContext context, UIComponent
component, Object value) {
[...]
    }

}

On Sat, Apr 13, 2013 at 7:40 AM, Howard W. Smith, Jr.
<sm...@gmail.com> wrote:
> In an effort to remove 'static' declarations throughout my app (to help
> JVM's GC), I removed 'static' from the definition of the Converter class
> below. So that resulted in the infamous error below:
>
> Apr 13, 2013 4:10:38 AM org.apache.myfaces.application.ApplicationImpl
> internalCreateConverter
> SEVERE: Could not instantiate converter
> jsf.CustomerController$CustomerControllerConverter
> java.lang.InstantiationException:
> jsf.CustomerController$CustomerControllerConverter
> at java.lang.Class.newInstance0(Unknown Source)
> at java.lang.Class.newInstance(Unknown Source)
> at
> org.apache.myfaces.application.ApplicationImpl.internalCreateConverter(ApplicationImpl.java:1626)
> at
> org.apache.myfaces.application.ApplicationImpl.createConverter(ApplicationImpl.java:1545)
> at
> javax.faces.application.ApplicationWrapper.createConverter(ApplicationWrapper.java:158)
>
> I assume 'static' is necessary, because only one copy of the class is
> created per application. Correct? So, can I define the class as a
> @Singleton @Lock(READ) to resolve the issue?
>
> Per NetBeans generated JSF controller/bean code, the Converter is usually
> defined in the same .java file as the controller or @ManagedBean. Honestly,
> I do 'not' want to use addConverter() or converterId="..." in the xhtml. I
> prefer to use @FacesConverter, since this has been working for me
> throughout the app.
>
>
>     package jsf;
>
>     import jpa.entities.Customer;
>     import jpa.session.CustomerFacade;
>
>     import java.io.Serializable;
>     import javax.ejb.EJB;
>     import javax.faces.bean.ManagedBean;
>     import javax.faces.bean.RequestScoped;
>     import javax.faces.component.UIComponent;
>     import javax.faces.context.FacesContext;
>     import javax.faces.convert.Converter;
>     import javax.faces.convert.FacesConverter;
>
>     @ManagedBean(name = "customerController")
>     @RequestScoped
>     public class CustomerController implements Serializable {
>
>         @EJB
>         private jpa.session.CustomerFacade ejbFacade;
>
>         public CustomerController() {
>         }
>
>         @FacesConverter(forClass = Customer.class)
>         public class CustomerControllerConverter implements Converter {
>
>             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.NumberFormatException.forInputString(NumberFormatException.java:65)
>                         at java.lang.Integer.parseInt(Integer.java:492)
>                         at java.lang.Integer.valueOf(Integer.java:582)
>                         at
> jsf.pointOfContact.pf_PointOfContactController$PointOfContactControllerConverter.getKey(pf_PointOfContactController.java:1625)
>                         at
> jsf.pointOfContact.pf_PointOfContactController$PointOfContactControllerConverter.getAsObject(pf_PointOfContactController.java:1620)
>                         at
> org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValue(AutoCompleteRenderer.java:529)
>                         at
> javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
>                         at
> javax.faces.component.UIInput.validate(UIInput.java:960)
>                  *
>                  */
>                 try {
>                     Integer test = getKey(value);
>                 } catch (java.lang.NumberFormatException e) {
>                     return null;
>                 }
>                 CustomerController controller = (CustomerController)
> facesContext.getApplication().getELResolver().
>                         getValue(facesContext.getELContext(), null,
> "customerController");
>                 return controller.ejbFacade.find(getKey(value));
>             }
>
>             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();
>                 sb.append(value);
>                 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: " +
> Customer.class.getName());
>                 }
>             }
>         }
>     }
>
>
> Thanks,
> Howard