2

私はすでにそれらを見ました:

ターゲットに到達できず、JSF 2.2 で識別子が null に解決される

SEAM の「ターゲットに到達できません。識別子 'authenticator' が null に解決されました」

Java EE 6: ターゲットに到達できません。識別子 'helloBean' が null に解決されました

ターゲットに到達できません。識別子「Bean 名」が null に解決されました

ターゲットに到達できません。識別子「Bean 名」が null に解決されました

JSF: /index.xhtml @12,80 value="#{LoginBean.username}": ターゲットに到達できません。識別子 'LoginBean' が null に解決されました

http://www.coderanch.com/t/598907/JSF/java/Target-unreachable-identifier-resolved-null

しかし、どれも私のために働いていませんでした。

ログイン.xhtml:

<?xml version="1.0" encoding="UTF-8" ?>
<!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:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login Page</title>
</head>
<body>
    <h:form prependId="false">

        <h3>WELLCOME</h3>
        <br />
        <h3>Enter</h3>
        <table>
            <tr>
                <td><h3>Name</h3></td>
                <td><h:inputText value="#{user.name}" id="name" /></td>
            </tr>
            <tr>
                <td><h3>password</h3></td>
                <td><h:inputSecret value="#{user.password}" id="password" /></td>
            </tr>
        </table>

        <h:commandButton value="Login">
            <f:ajax execute="name password" render="out" />
        </h:commandButton>
        <h3>
            <h:outputText id="out" value="#{user.greeting}" />
        </h3>

    </h:form>
</body>
</html>

ユーザー.java:

import java.io.Serializable;

import javax.annotation.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class User implements Serializable {

    private String name;
    private String password;
    private String greeting;

    public String getGreeting() {
        if (name.length() == 0)
            return "";
        else
            return "Welcome to JSF2 + Ajax, " + name + "!";
    }

    public String getName() {
        return name;
    }

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

    public String getPassword() {
        return password;
    }

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

    public void setGreeting(String greeting) {
        this.greeting = greeting;
    }

}

私が知っているように、jsf2.2はそれ自体を行うため、これらのweb.xmlを構成しませんでした。

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Ajax</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <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>/faces/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
</web-app>

構成面:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">

</faces-config>

エラーはボタンをクリックしたときです:

        HTTP Status 500 - /Login.xhtml @17,78 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null

    --------------------------------------------------------------------------------

    type Exception report

    message /Login.xhtml @17,78 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null

    description The server encountered an internal error that prevented it from fulfilling this request.

    exception 

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'user' resolved to null
    at org.apache.el.parser.AstValue.getTarget(AstValue.java:98)
    at org.apache.el.parser.AstValue.getType(AstValue.java:82)
    at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:172)
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
    at javax.faces.component.UIInput.validate(UIInput.java:976)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
    at javax.faces.component.UIInput.processValidators(UIInput.java:712)
    at javax.faces.component.UIForm.processValidators(UIForm.java:253)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
    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:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    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:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    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:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

そして、この警告:

Typee value of the field User.greeting is not used  

しかし、同じ get と set を持つ 2 つの文字列がありますが、警告はありません。

Tomcat 7.0.54 を使用しています。

4

3 に答える 3

3

現在のコードにはかなりの誤りがあります:

  1. 間違った JSF アノテーションを使用している

  2. JSF 標準タグを使用していません。使用する:

    • <h:head/>(これはjsf<head>のほとんどの ajax 機能に必要ですこれがないと、ajax をサポートするために必要な JavaScript をページに含めることができません。
    • <h:body>それ以外の<body>

HTTP-500 は、コードに実際のバグがあることを示しています。

于 2014-06-20T21:37:29.560 に答える
2

別の注釈を使用してみてください

import javax.faces.bean.ManagedBean;

Java EE 6 の代わりに

import javax.annotation.ManagedBean;
于 2014-06-20T11:50:07.310 に答える