You cant use faces context? Le 20 nov. 2012 03:01, "Howard W. Smith, Jr." <smithh032...@gmail.com> a écrit :
> For minimal changes, I'm adding FacesConverter to JSF requestscoped > managedBean's as per the Stackoverflow answer below: > > How can I inject in @FacesConverter?< > http://stackoverflow.com/a/13156834/933054> > > Yes, this means more classes in the project, but honestly, I have not had > to spend much time 'maintaining' my Converter classes at all. I just tested > this concept, and I'm not experiencing this exceptioin any more. > > While testing the above, I see more exceptions to resolve related to > migrating to CDI. Will let you all know, if I have any more questions. > > Thanks for all the responses/help, so far. :) > > > > On Mon, Nov 19, 2012 at 7:20 PM, Romain Manni-Bucau > <rmannibu...@gmail.com>wrote: > > > If it is a nested class you need it otherwise (class foo in foo.java > file) > > you dont need it > > Le 20 nov. 2012 01:16, "Howard W. Smith, Jr." <smithh032...@gmail.com> a > > écrit : > > > > > Good question. I removed 'static', because I didn't see it in the code > at > > > following URLs: > > > > > > > > > > > > https://cwiki.apache.org/confluence/display/EXTCDI/JSF+Usage#JSFUsage-DependencyInjection > > > > > > > > > > > > http://stackoverflow.com/questions/7531449/cdi-injection-into-a-facesconverter > > > > > > https://issues.apache.org/jira/browse/EXTCDI-127 > > > > > > > > > On Mon, Nov 19, 2012 at 4:30 PM, Romain Manni-Bucau > > > <rmannibu...@gmail.com>wrote: > > > > > > > Why removing static? It means it is no more manageable by cdi (cdi > cant > > > do > > > > a new on it) > > > > Le 19 nov. 2012 22:13, "Howard W. Smith, Jr." < > smithh032...@gmail.com> > > a > > > > écrit : > > > > > > > > > @Advanced was found in the following: > > > > > > > > > > import org.apache.myfaces.extensions.cdi.core.api.Advanced; > > > > > > > > > > After some tinkering, I removed 'static' from the following > > definition, > > > > > > > > > > public static class AddressTypeControllerConverter implements > > > Converter { > > > > > > > > > > I also added @Advanced to the FacesConverter/Converter, and latest > > > error > > > > is > > > > > the following: > > > > > > > > > > Nov 19, 2012 4:08:21 PM > javax.faces.component._ExternalSpecifications > > > > > isBeanValidationAvailable > > > > > INFO: MyFaces Bean Validation support enabled > > > > > Nov 19, 2012 4:08:21 PM > > org.apache.myfaces.application.ApplicationImpl > > > > > internalCreateConverter > > > > > SEVERE: Could not instantiate converter class > > > > > jsf.address.pf_AddressTypeController$AddressTypeControllerConverter > > > > > java.lang.InstantiationException: > > > > > jsf.address.pf_AddressTypeController$AddressTypeControllerConverter > > > > > > > > > > > > > > > > > > > > On Mon, Nov 19, 2012 at 3:07 PM, Howard W. Smith, Jr. < > > > > > smithh032...@gmail.com> wrote: > > > > > > > > > > > I searched google, found the following: > > > > > > > > > > > > CDI Injection into a FacesConverter< > > > > > > > > > > > > > > > http://stackoverflow.com/questions/7531449/cdi-injection-into-a-facesconverter > > > > > > > > > > > > > > > > > > which lead me to: > > > > > > > > > > > > MyFaces Extensions CDI > JSF Usage > Dependency Injection< > > > > > > > > > > > > > > > https://cwiki.apache.org/confluence/display/EXTCDI/JSF+Usage#JSFUsage-DependencyInjection > > > > > > > > > > > > > > > > > > but I don't which library to import for @Advanced. > > > > > > > > > > > > If @Advanced can be used (since I am using CODI), then this would > > be > > > > > great. > > > > > > > > > > > > > > > > > > On Mon, Nov 19, 2012 at 2:56 PM, Romain Manni-Bucau < > > > > > rmannibu...@gmail.com > > > > > > > wrote: > > > > > > > > > > > >> Maybe use BeanProvider of deltaspike > > > > > >> Le 19 nov. 2012 20:50, "Howard W. Smith, Jr." < > > > smithh032...@gmail.com > > > > > > > > > > a > > > > > >> écrit : > > > > > >> > > > > > >> > Hmmm... after thinking about it, I remembered to use @Inject > on > > > the > > > > > bean > > > > > >> > which I want to inject. So, I did the following: > > > > > >> > > > > > > >> > @FacesConverter(forClass = AddressType.class) > > > > > >> > public static class AddressTypeControllerConverter > > implements > > > > > >> Converter > > > > > >> > { > > > > > >> > > > > > > >> > @Inject > > > > > >> > private pf_AddressTypeController controller; > > > > > >> > > > > > > >> > public Object getAsObject(FacesContext facesContext, > > > > > UIComponent > > > > > >> > component, String value) { > > > > > >> > if (value == null || value.length() == 0) { > > > > > >> > return null; > > > > > >> > } > > > > > >> > return controller.ejbFacade.find(getKey(value)); > > > > > >> > } > > > > > >> > > > > > > >> > but 'controller' is still not being injected. I even tried the > > > same > > > > > for > > > > > >> the > > > > > >> > actual 'ejbFacade' (which is a stateless bean), but that, too, > > > > > resulted > > > > > >> in > > > > > >> > a NullPointerException, which tells me that @Inject is not > > > injecting > > > > > >> > pf_AddressTypeController (@sessionscoped bean) OR ejbFacade > > > > > (@Stateless > > > > > >> > bean instance of AddressTypeFacade). > > > > > >> > > > > > > >> > > > > > > >> > Is there a general practice used for injecting beans in > > > Converters.. > > > > > >> > > > > > > >> > > > > > > >> > > > > > > >> > On Mon, Nov 19, 2012 at 2:38 PM, Romain Manni-Bucau > > > > > >> > <rmannibu...@gmail.com>wrote: > > > > > >> > > > > > > >> > > Can you reproduce it in a sample? What is on the npe line? > > > > > >> > > Le 19 nov. 2012 20:25, "Howard W. Smith, Jr." < > > > > > smithh032...@gmail.com> > > > > > >> a > > > > > >> > > écrit : > > > > > >> > > > > > > > >> > > > I am still migrating my app from JSF Managed beans to CDI > > > > managed > > > > > >> > beans, > > > > > >> > > so > > > > > >> > > > I am (regression) testing, and I came across the exception > > > below > > > > > >> when > > > > > >> > > > attempting to add a record into the database on one of the > > > xhtml > > > > > >> pages. > > > > > >> > > > > > > > > >> > > > Caused by: java.lang.NullPointerException > > > > > >> > > > at > > > > > >> > > > > > > > > >> > > > > > > > >> > > > > > > >> > > > > > > > > > > > > > > > jsf.address.pf_AddressTypeController$AddressTypeControllerConverter.getAsObject(pf_AddressTypeController.java:283) > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > The exception is caused by this line below. *ejbFacade* > is a > > > > > >> stateless > > > > > >> > > bean > > > > > >> > > > injected by @Inject. > > > > > >> > > > > > > > > >> > > > return > > controller.*ejbFacade*.find(getKey(value)); > > > > > >> > > > > > > > > >> > > > > > > > > >> > > > The code below is as-is using JSF Managed Beans. Please > > advise > > > > on > > > > > >> how I > > > > > >> > > > should update the following code, so it will work well > with > > > CDI. > > > > > >> > > > > > > > > >> > > > @FacesConverter(forClass = AddressType.class) > > > > > >> > > > public static class AddressTypeControllerConverter > > > > implements > > > > > >> > > Converter > > > > > >> > > > { > > > > > >> > > > > > > > > >> > > > public Object getAsObject(FacesContext > facesContext, > > > > > >> > UIComponent > > > > > >> > > > component, String value) { > > > > > >> > > > if (value == null || value.length() == 0) { > > > > > >> > > > return null; > > > > > >> > > > } > > > > > >> > > > pf_AddressTypeController controller = > > > > > >> > > > (pf_AddressTypeController) > > > > > >> > facesContext.getApplication().getELResolver(). > > > > > >> > > > getValue(facesContext.getELContext(), > > > null, > > > > > >> > > > "pf_addressTypeController"); > > > > > >> > > > 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 AddressType) { > > > > > >> > > > AddressType o = (AddressType) object; > > > > > >> > > > return getStringKey(o.getAddressTypeId()); > > > > > >> > > > } else { > > > > > >> > > > throw new IllegalArgumentException("object > > " + > > > > > >> object > > > > > >> > + " > > > > > >> > > > is of type " + object.getClass().getName() + "; expected > > type: > > > > " + > > > > > >> > > > pf_AddressTypeController.class.getName()); > > > > > >> > > > } > > > > > >> > > > } > > > > > >> > > > } > > > > > >> > > > } > > > > > >> > > > > > > > > >> > > > > > > > >> > > > > > > >> > > > > > > > > > > > > > > > > > > > > > > > > > > >