Return-Path: X-Original-To: apmail-myfaces-users-archive@www.apache.org Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A82DDF378 for ; Sun, 14 Apr 2013 00:58:34 +0000 (UTC) Received: (qmail 6748 invoked by uid 500); 14 Apr 2013 00:58:34 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 6708 invoked by uid 500); 14 Apr 2013 00:58:33 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 6700 invoked by uid 99); 14 Apr 2013 00:58:33 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Apr 2013 00:58:33 +0000 X-ASF-Spam-Status: No, hits=1.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of smithh032772@gmail.com designates 209.85.212.180 as permitted sender) Received: from [209.85.212.180] (HELO mail-wi0-f180.google.com) (209.85.212.180) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Apr 2013 00:58:29 +0000 Received: by mail-wi0-f180.google.com with SMTP id c10so587793wiw.1 for ; Sat, 13 Apr 2013 17:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=gJ3aU6PXgiXmzVcoVkTBBP+PWJajrOjaFqSCI8BmSOg=; b=GyxmB0OZCxmYZaQNf5YdfkDFXDesFeIRPjX+lJfW6Uzknqssr8zbdgK/rl5yx0RFiq 1U9GXRQws1kuzJ5deoVKd6xjfY4SmRQUY7aHtsJNMAyJDdxtmxrgQTPktCKieARvqs/p pSrA0KiQMKBXTBI+cFPqGI4qRwzSP6uMbir5+pPgynihaXsAZFmGlmJuPO346HcY5Vjb 96YI4I00M/FiDEhsxuRfeab5qDydknvzT/JTIp5B0TK+DUKmwf0kWwq1kJvqnHu1PmXA ULaMfTiOpPWz270nPunQRMg0ZJs+SkmoeBrBn1AzbjcePCHR+qPAIBWojdRW639CBoka noEg== MIME-Version: 1.0 X-Received: by 10.180.97.132 with SMTP id ea4mr4905294wib.23.1365901088444; Sat, 13 Apr 2013 17:58:08 -0700 (PDT) Received: by 10.227.25.194 with HTTP; Sat, 13 Apr 2013 17:58:08 -0700 (PDT) In-Reply-To: References: Date: Sat, 13 Apr 2013 20:58:08 -0400 Message-ID: Subject: Re: @Singleton @Lock(READ) to resolve, Could not instantiate converter ... From: "Howard W. Smith, Jr." To: MyFaces Discussion Content-Type: multipart/alternative; boundary=f46d04426c4e2cd70304da47a179 X-Virus-Checked: Checked by ClamAV on apache.org --f46d04426c4e2cd70304da47a179 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sat, Apr 13, 2013 at 1:00 PM, Jos=E9 Luis Cetina w= rote: > 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=F3: > > Jos=E9, 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 =3D 1, unit =3D TimeUnit.MINUTES) @FacesConverter(forClass =3D Customer.class) public class CustomerConverter implements Converter { public CustomerConverter() { } public Object getAsObject(FacesContext facesContext, UIComponent component, String value) { if (value =3D=3D null || value.length() =3D=3D 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:6= 5) at java.lang.Integer.parseInt(Integer.java:492) at java.lang.Integer.valueOf(Integer.java:582) ... ... at org.primefaces.component.autocomplete.AutoCompleteRenderer.getConvertedValu= e(AutoCompleteRenderer.java:529) at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) at javax.faces.component.UIInput.validate(UIInput.java:960) * */ try { Integer test =3D getKey(value); } catch (java.lang.NumberFormatException e) { return null; } Object object =3D null; CustomerFacade ejbFacade; try { InitialContext ic =3D new InitialContext(); ejbFacade =3D (CustomerFacade) ic.lookup("java:global/mcmsweb/CustomerFacade"); if (ejbFacade =3D=3D null) { System.err.println("CustomerConverter.getAsObject(): ejbFacade =3D null)"); return null; } } catch (Exception e) { System.err.println("CustomerConverter.getAsObject(): error on JNDI lookup of CustomerFacade"); e.printStackTrace(); return null; } try { object =3D 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 =3D Integer.valueOf(value); return key; } String getStringKey(java.lang.Integer value) { StringBuffer sb =3D new StringBuffer(); sb.append(value); return sb.toString(); } public String getAsString(FacesContext facesContext, UIComponent component, Object object) { if (object =3D=3D null) { return null; } if (object instanceof Customer) { Customer o =3D (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/READM= E.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 --f46d04426c4e2cd70304da47a179--