在JDevelper和Weblogic

时间:2015-10-14 20:49:50

标签: jsf jsf-2 weblogic java-ee-7

我认为this question与我有关,但我不想在项目中添加另一个jar。

我正在将netbeans和Glassfish中的java hello1 example (JEE7)(以及您将会看到的一些修改)迁移到JDeveloper 12.1.3和Weblogic Server 12.1.3.0.0。我这样做是因为我需要用jsf启动一个项目,我需要这些IDE和Server。问题是我无法在我的支持bean中使用带有@Named注释的CDI。

添加到我的项目中的库是" JSP Runtime",JSF 2.1和JSTL 1.2

JDeveloper建议我"为CDI配置项目"所以它在WEB-INF目录下添加了一个新库,#34;上下文和依赖注入"以及beans.xml文件。

的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>

当我运行项目时,响应为空&#34;您好&#34;并且没有显示name属性,但没有错误。

如果我删除&#34;上下文和依赖注射&#34;库和beans.xml文件然后它显示以下错误:

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)

如果我使用@ManagedBean注释而不是@Named注释,一切正常。任何建议将不胜感激,提前谢谢。

这是我的代码

的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>

项目结构

ViewController
    |-src
    |   |-view
    |        |-backing
    |                |-Batch.java
    |-public_html
    |          |-index.xhtml
    |          |-response.xhtml
    |          |-WEB-INF
    |                  |-web.xml

1 个答案:

答案 0 :(得分:0)

As Geinmachi said我使用了错误的导入。在java ee 7教程中,您可以看到一个示例(example