I think that this question is related to mine, but i wouldn't like to add another jar to the project.
I am migrating the java hello1 example (JEE7)(with some modifications that you'll see bellow) from netbeans and Glassfish to JDeveloper 12.1.3 and Weblogic Server 12.1.3.0.0. I'm doing this because I need to start a project with jsf and I need these IDE and Server. The problem is that I can't use CDI with the @Named annotation in my backing bean.
The Libraries added to my project are "JSP Runtime", JSF 2.1 and JSTL 1.2
JDeveloper suggest me "Configure Project for CDI" so It adds a new library, "Contexts and Dependendcy Injection", and beans.xml file under WEB-INF directory.
beans.xml
<?xml version = '1.0' encoding = 'windows-1252'?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd" xmlns="http://java.sun.com/xml/ns/javaee"></beans> When I run the project the response is empty "Hello" and the name property is not showed, but without errors.
If I remove the "Contexts and Dependendcy Injection" library and the beans.xml file then it shows me the following error:
Error 500--Internal Server Error javax.el.PropertyNotFoundException: //C:/Users/edbuitrago/.jdeveloper/system12.1.3.0.41.140521.1008/o.j2ee/drs/Batch/ViewControllerWebApp.war/index.xhtml @8,49 value="#{batch.name}": Target Unreachable, identifier 'batch' resolved to null at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) at javax.faces.component.UIInput.validate(UIInput.java:960) at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) at javax.faces.component.UIInput.processValidators(UIInput.java:698) at javax.faces.component.UIForm.processValidators(UIForm.java:253) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220) at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1220) at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1164) at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:346) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:137) at java.security.AccessController.doPrivileged(Native Method) at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315) at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:460) at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:120) at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:217) at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:81) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:220) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:79) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3436) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3402) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57) at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2285) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2201) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2179) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1572) at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:255) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:311) at weblogic.work.ExecuteThread.run(ExecuteThread.java:263) Everything works fine if I use @ManagedBean annotation instead of @Named annotation. Any suggestions will be appreciated, thanks in advance.
Here is my code
index.xhtml
<?xml version='1.0' encoding='windows-1252'?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:head></h:head> <h:body> <h:form> <h2>Hello, my name is Duke. What's yours?</h2> <h:inputText value="#{batch.name}"/> <h:commandButton value="Send" action="response"/> </h:form> </h:body> </html> response.xhtml
<?xml version='1.0' encoding='windows-1252'?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:head></h:head> <h:body> <h2>Hello #{batch.name}</h2> </h:body> </html> Batch.java
package view.backing; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.inject.Named; @Named @RequestScoped public class Batch { private String name; public Batch(){ } public void setName(String name) { this.name = name; } public String getName() { return name; } } web.xml
<?xml version = '1.0' encoding = 'windows-1252'?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>/index.xhtml</welcome-file> </welcome-file-list> </web-app> project structure
ViewController |-src | |-view | |-backing | |-Batch.java |-public_html | |-index.xhtml | |-response.xhtml | |-WEB-INF | |-web.xml
@Nameduseimport javax.enterprise.context.RequestScoped