HTTP状态500 - JSF facelets应用程序中的null源

时间:2013-11-20 18:44:21

标签: jsf-2 facelets

我跟随tutorial并尝试了我的第一个JSF计划。这就是我到目前为止所做的:

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    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-facesconfig_2_0.xsd"
    version="2.0">
    <managed-bean>
        <managed-bean-name>loginBean</managed-bean-name>
        <managed-bean-class>com.tutorial.LoginBean</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <display-name>WEB-INF/template/Login.xhtml</display-name>
        <from-view-id>/WEB-INF/template/Login.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>login</from-outcome>
            <to-view-id>/WEB-INF/template/Welcome.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>

</faces-config>

BasicTemplate.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">
<head>
  <title><ui:insert name="title">Facelets Tutorial</ui:insert></title>
</head>

<body>

<div id="header">
    <ui:insert name="header">
        <ui:include src="/WEB-INF/template/Header.xhtml"/>
    </ui:insert>
</div>

<div id="content">
    <ui:insert name="content">
    </ui:insert>
</div>

<div id="footer">
    <ui:insert name="footer">
        <ui:include src="/WEB-INF/template/Footer.xhtml"/>
    </ui:insert>
</div>

</body>
</html>

Login.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">

<ui:composition template="/WEB-INF/template/BasicTemplate.xhtml">
    <ui:define name="content">
        <h:form>
            <h:panelGrid columns="2">
                <h:outputText value="Name"></h:outputText>
                <h:inputText value="#{LoginBean.name}"></h:inputText>
                <h:outputText value="Password"></h:outputText>
                <h:inputSecret value="#{LoginBean.password}"></h:inputSecret>
            </h:panelGrid>
            <h:commandButton value="Login" action="login"></h:commandButton>
        </h:form>
    </ui:define>
</ui:composition>
</html>

LoginBean.java

/**
 * LoginBean.java
 * 
 */

package com.tutorial;

public class LoginBean
{
    private String name;
    private String password;


    public String getName ()
    {
        return name;
    }


    public void setName (final String name)
    {
        this.name = name;
    }


    public String getPassword ()
    {
        return password;
    }


    public void setPassword (final String password)
    {
        this.password = password;
    }
}

然而,当我运行它时,它会抛出以下异常:

java.lang.IllegalArgumentException: null source
    at java.util.EventObject.<init>(Unknown Source)
    at javax.faces.event.SystemEvent.<init>(SystemEvent.java:67)
    at javax.faces.event.ComponentSystemEvent.<init>(ComponentSystemEvent.java:69)
    at javax.faces.event.PostRestoreStateEvent.<init>(PostRestoreStateEvent.java:69)
    at com.sun.faces.lifecycle.RestoreViewPhase.deliverPostRestoreStateEvent(RestoreViewPhase.java:256)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:245)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:107)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

这是如何引起的?如何解决?

2 个答案:

答案 0 :(得分:0)

/WEB-INF中的文件无法公开访问。该文件夹用于配置文件,模板文件,包含文件等,但不适用于公共页面和模板客户端。

您需要分别将/WEB-INF/template/Login.xhtml/WEB-INF/template/Welcome.xhtml移至/Login.xhtml/Welcome.xhtml并相应地更改<navigation-rule>

<navigation-rule>
    <from-view-id>/Login.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>login</from-outcome>
        <to-view-id>/Welcome.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

你所面临的例外实际上是一个误导性的例外,可以认为是来自一个相当古老的Mojarra 2.0.x版本(固定在2.0.5左右)。如果您升级到更新的Mojarra版本,那么您应该获得更加自我解释的FacesFileNotFoundException

另见:

答案 1 :(得分:0)

Thanks for the response. it worked and the page is up but after that the page did not navigate to the next page and sorry i have pasted the same line again and again as it has requested for extra lines.

exception 

javax.servlet.ServletException: /template/Login.xhtml @14,56 value="#{LoginBean.name}": Target Unreachable, identifier 'LoginBean' resolved to null
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)


root cause 

javax.el.PropertyNotFoundException: /template/Login.xhtml @14,56 value="#{LoginBean.name}": Target Unreachable, identifier 'LoginBean' resolved to null
    com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:97)
    com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:91)
    javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
    javax.faces.component.UIInput.validate(UIInput.java:953)
    javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
    javax.faces.component.UIInput.processValidators(UIInput.java:693)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    javax.faces.component.UIForm.processValidators(UIForm.java:240)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
    javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
    com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)