Cannot find @Named CDI bean with default name in EL / Facelet

In the jee6 tutorial, I can read the following:

The @Named qualifier allows you to access a bean using the name bean, with the first letter in lowercase. For example, the Facelets Page will refer to the bean as a printer.

You can specify an argument for the @Named classifier to use a nondefault name:

However, when I try to use @Named without adding an argument, My bean cannot be found, and I get an exception, as shown below.

@Named
@ViewScoped
public class MTestBean {
...
}

An exception;

javax.servlet.ServletException: /MyPage.xhtml @15,65 listener="#{mTestBean.init}": Target Unreachable, identifier 'mTestBean' resolved to null

But if I use

@Named("mTestBean")

Everything works perfectly. Is this expected behavior? Is there any way I can list that beans are available in EL, maybe I am assuming the wrong default name?

+4
1

bean, # {MTestBean.xxx}. , NetBeans # {mTestBean.xxx}. BalusC, JavaBeans. 8.8 -

... , , , if . , , "FooBah" "fooBah" "Z" "z" "URL" "URL", Introspector.decapitalize, .

beans CDI, javax.enterprise.inject.spi.BeanManager. .

EDIT: , EL, .

public void listAllBeans() throws NamingException{
        //Get the BeanManager
        InitialContext initialContext = new InitialContext();
        BeanManager bm = (BeanManager) initialContext.lookup("java:comp/BeanManager");

        //List all CDI Managed Beans and their EL-accessible name
        Set<Bean<?>> beans = bm.getBeans(Object.class,new AnnotationLiteral<Any>() {});
        for (Bean<?> bean : beans) {
            System.out.println(bean.getBeanClass().getName() + " / bean name = " + bean.getName());
        }
    }

bean -

com.xxx.jsf.beans.MTestBean/bean name = MTestBean

+6

All Articles