CDI Injection into a FacesConverter

Replace @FacesConverter(value = “categoryConverter”) by @Named and use <h:inputSomething converter=”#{categoryConverter}” /> or <f:converter binding=”#{categoryConverter}” /> instead of <h:inputSomething converter=”categoryConverter” /> or <f:converter converterId=”categoryConverter” /> By the way, similar problem exist for @EJB inside a @FacesConverter. It however offers a way to be grabbed by JNDI manually. See also Communication in JSF 2.0 – Getting an … Read more

JSF does not populate @Named @RequestScoped bean with submitted input values

From your bean: import javax.faces.bean.RequestScoped; import javax.inject.Named; @Named(“loginRequest”) @RequestScoped public class LoginRequest { You’re mixing CDI and JSF annotations. You can and should not do that. Use the one or the other. I don’t know what’s the book is telling you, but most likely you have chosen the wrong autocomplete suggestion during the import of … Read more

NullPointerException while trying to access @Inject bean in constructor

You’re expecting that the injected dependency is available before the bean is constructed. You’re expecting that it works like this: RequestBean requestBean; requestBean.sessionBean = sessionBean; // Injection. requestBean = new RequestBean(); // Constructor invoked. This is however not true and technically impossible. The dependencies are injected after construction. RequestBean requestBean; requestBean = new RequestBean(); // … Read more

How do CDI and EJB compare? interact?

It is currently indeed a bit confusing as there are now multiple component models in Java EE. They are CDI, EJB3 and JSF Managed Beans. CDI is the new kid on the block. CDI beans feature dependency injection, scoping and an event bus. CDI beans are the most flexible with respect to injection and scoping. … Read more

Where to use EJB 3.1 and CDI?

Yes, you can freely mix both CDI and EJB and achieve some great results. It sounds like you are using @WebService and @Schedule, which are good reasons for adding EJB to the mix. There’s a lot of confusion out there, so here is some general information on EJB and CDI as they relate to each … Read more

Field.get(obj) returns all nulls on injected CDI managed beans, while manually invoking getters return correct values

That’s indeed expected behavior. The CDI managed bean instance is in essence a serializable proxy instance of an autogenerated class which extends the original backing bean class and delegates in all public methods further to the actual instance via public methods (like as how EJBs work). The autogenerated class looks roughly like this: public CDIManagedBeanProxy … Read more

Changing faces-config.xml from 2.2 to 2.3 causes javax.el.PropertyNotFoundException: Target Unreachable, identifier ‘bean’ resolved to null

I would like to post a complete solution, what should be done in order to make JSF 2.3 libs work in JSF v2.3 mode. Code samples below are based on GlassFish 5.0 server environment. 1) Upgrade JSF libs to the version 2.3.3 at least (it fixes some bugs related to jsf 2.3 mode activation) 2) … Read more