I am getting this exception when I try deploying my application to Glassfish Server:
org.jboss.weld.exceptions.DeploymentException: WELD-001409 Ambiguous
dependencies for type [FileReferenceDao] with qualifiers [#Default] at
injection point [[BackedAnnotatedField] #Inject
com.tugay.fup.web.MyUploadedFilesBean.fileReferenceDao]. Possible
dependencies [[Session bean [class
com.tugay.fup.core.dao.FileReferenceDao with qualifiers [#Any
#Default]; local interfaces are [FileReferenceDao], Session bean
[class com.tugay.fup.core.dao.FileReferenceDao with qualifiers [#Any
#Default]; local interfaces are [FileReferenceDao]]]
The interesting part is
Possible dependencies [[Session bean [class
com.tugay.fup.core.dao.FileReferenceDao with qualifiers [#Any
#Default]; local interfaces are [FileReferenceDao], Session bean
[class com.tugay.fup.core.dao.FileReferenceDao with qualifiers [#Any
#Default]; local interfaces are [FileReferenceDao]]]
What is going on in here?
I only have one FileReferenceDao, which has no Interface or anything else. It does not extend any other class. And this is how I use it:
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
#Named
#RequestScoped
public class MyUploadedFilesBean {
#Inject
FileReferenceDao fileReferenceDao;
Everything was working fine until 15 minutes ago.
I tried mixing JSF Managed beans with CDI beans, it did not work, I rolled - back. Now I am getting this exception.
#Stateless public class FileReferenceDao {
#PersistenceContext(unitName = "Persistence")
EntityManager em;
Related
I'm using JBoss EAP 6.4 (and Weld 1.1.28) and trying to get rid of Seam 2. One part of that is switching over to CDI. I get the following (anonymized) error:
org.jboss.weld.exceptions.DeploymentException: WELD-001443 Pseudo scoped bean
has circular dependencies. Dependency path
[Managed Bean [A] with qualifiers [#Default #Any #Named],
Managed Bean [B] with qualifiers [#Default #Any],
Managed Bean [C] with qualifiers [#Default #Any],
Managed Bean [D] with qualifiers [#Default #Any],
Managed Bean [C] with qualifiers [#Default #Any]]
Every single one of these is #SessionScoped, however, so it seems like this should work since #SessionScoped is a "normal" scope. Why doesn't this work?
#SessionScoped for CDI is javax.enterprise.context.SessionScoped. If you happen to annotate class with javax.faces.bean.SessionScoped then your class is not managed by CDI. When you try to #Inject it then it will be #Dependent pseudo-scoped.
I'm having a little issue with OmniFaces's Viewscoped. Even with my Managedbean implementing Serializable, I'm receiving the error below:
Passivation capable beans must satisfy passivation capable dependencies.
With some research, I found some answers about the this problem but with no success. I resolved my problem serializing my other class that I'm injecting with CDI.
Is it really necessary my other classes implementing Serializable to Inject in my Managedbean?
Environment
- WebSphere Application Server 8.5.5.2
- Apache MyFaces 2.0.2
- OmniFaces 1.7
- PrimeFaces 5.0
My Class:
public class AgrupamentoAcoRN{
#Inject
public TbSiglaAcoAgrupadaDAO dao;
public void insereDados(TbSiglaAcoAgrupada tbSiglaAcoAgrupada) throws BancoDeDadosException{
dao.insereRegistro(tbSiglaAcoAgrupada);
}
}
My Bean:
#Named("agrupamentoAcoMb")
#ViewScoped
public class AgrupamentoAcoMB implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
#Inject
private AgrupamentoAcoRN rn;
}
All fields of a Serializable java class should be serializable, hence every field in your viewScoped bean should be serializable also.
Your problem have nothing to do with Omnifaces
I have a problem with JSF, CDI project. I did a lot of research and I found that in CDI there is no #ViewedScoped annotation. I solving problem with ajax based page with dialog. I want to pass variable to dialog from datatable. For this purpose, I can't use #RequestedScoped bean because value is discard after end of request. Can anyone help me to solve it? I can't use #SessionScoped but it's a bad practice IMHO. Or maybe save only this one variable into session who knows. Can you guys give me any hints how to solve this problem elegantly?
import javax.enterprise.context.ApplicationScoped;
#ApplicationScoped
public class ServiceBean implements Serializable {
...
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
#ManagedBean
#ViewScoped
public class SomeBean {
#Inject
ServiceBean serviceBean;
#Postconstruct ...
Here is the error message:
com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean warDetailBean
First, If you are attempting to use CDI, you need to activate it by putting a WEB-INF/beans.xml file in your application (note that this file can be empty), more informations about that file could be found in the Weld - JSR-299 Reference Implementation.
As you are using Tomcat, please be sure to respect all the configuration requirements by following the steps in How to install CDI in Tomcat?
Second, Even if you can use #Inject inside a JSF managed bean, It's preferable that you don't mix JSF managed beans and CDI, please see BalusC's detailed answer regarding Viewscoped JSF and CDI bean.
So if you want to work only with CDI #Named beans, you can use OmniFaces own CDI compatible #ViewScoped:
import javax.inject.Named;
import org.omnifaces.cdi.ViewScoped;
#Named
#ViewScoped
public class SomeBean implements Serializable {
#Inject
ServiceBean serviceBean;
}
Or, if you want to work only with JSF managed beans, you can use #ManagedProperty to inject properties:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
#ManagedBean
#ViewScoped
public class SomeBean{
#ManagedProperty(value = "#{serviceBean}")
ServiceBean serviceBean;
}
See also:
ManagedProperty in CDI #Named bean returns null
Omnifaces CDI ViewScoped
how can I Inject a Bean, that uses a #Named annotation along with a value?
#Named
public class LanguageService{
...
}
public class SomeOtherBean{
#Inject
private LanguageService languageService
}
works without Problem - but how to inject, if i'm using:
#Named("lang")
public class LanguageService{
...
}
#Inject can't have a value as #ManagedProperty does. (But I wan't to stay with CDI)
Edit:
I noticed that it doesn't matter how the bean is named. My Fault that leads to an NPE was simple that i created SomeOtherBean manually, and ofc. no Injection was done. My fault.
CDI selects injectable beans by type (and qualifiers) and not by the annotation parameter. The name is used to address a CDI bean from views, e.g. facelets.
I have two web jsf projects which potentially could share some classes and beans, to reduce code duplicates.
One is a potential JNDI-ServiceLocator application scoped Bean. (Both web projects access RemoteBeans from same Host)
JNDI - ServiceLocator Bean:
#ManagedBean(name = "jndiServiceLocatorBean")
#ApplicationScoped
public class JndiServiceLocatorBean implements Serializable
{
// code to cache jndi references
}
Abstract class with Bean as ManagedProperty:
public abstract class AJndiServiceLocator
{
#ManagedProperty(value = "#{jndiServiceLocatorBean}")
protected JndiServiceLocatorBean jndiServiceLocatorBean = null;
public void setJndiServiceLocatorBean(final JndiServiceLocatorBean jndiServiceLocatorBean)
{
this.jndiServiceLocatorBean = jndiServiceLocatorBean;
}
}
Example Bean from one of the projects:
#ManagedBean(name = "testBean")
#ApplicationScoped
public class TestBean extends AJndiServiceLocator implements Serializable
{
// bean code - can now retrieve remote bean interfaces
// from super class
}
This code works as expected if the first classes JndiServiceLocatorBean and AJndiServiceLocator are in the source folder of the project.
But it does not works if I outsource those two classes into a subproject that is shared between both web projects. (Included on build path and marked as deployment entry.)
Injection Exception that occurs:
Schwerwiegend: Error Rendering View[/index.xhtml]
com.sun.faces.mgbean.ManagedBeanCreationException: Bei der Ressourcen-Einspeisung auf dem verwalteten Bean appBean ist ein Fehler aufgetreten.
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:229)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
JSF won't scan every single JAR in the entire classpath for JSF artifacts, that would have been a very expensive job in a large webapp with tens of JARs. JSF will only scan JARs in /WEB-INF/lib folder containing a JSF 2.0 compatible /META-INF/faces-config.xml file.
Ensure that your JAR conforms this.
It must be in /WEB-INF/lib.
It must have a /META-INF/faces-config.xml with a JSF 2.0 compatible root declaration.
See also:
Structure for multiple JSF projects with shared code
JSF facelets template packaging