I went to use CDI beans as beans support instead of JSF managed beans.
So, I decided to create a small example to understand how it works for @RequestScopedBean :
- instead of using @ManagedBean ("beanName") , I use @Named ("beanName")
- instead of using javax.faces.bean.RequestScopped I use javax.enterprise.context.RequestScoped;
The demo program is very simple: I have a field and a submit button, when the user enters something, and the page refreshes, the entered value is no longer displayed (does it continue while the request lasts the same?). I think everything was doing fine, but I get an exception that says:
WARNING: StandardWrapperValve [Persons Servlet]: PWC1406: Servlet.service () for servlet exception javax.el.PropertyNotFoundException: /index.xhtml @ 19.47 value = "# {cdiBean.passedValue}": Target Unreachable, identifier 'cdidian' id ' allowed null
This is what my program looks like:
index.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <title>RequestScope demo CDI(Component Dependency Injection)</title> </h:head> <h:body> <h:form> <h3>RequestScope demo CDI(Component Dependency Injection)</h3> <h:inputText value="#{cdiBean.passedValue}"/> <br/> <h:commandButton value="submit" action="index"/> </h:form> </h:body> </html>
DemoBB.java
package backingbeans; import javax.enterprise.context.RequestScoped; import javax.inject.Named; @Named("cdiBean")
βWhere is my mistake?β
- What is the advantage of using this approach? I still do not understand this.
source share