gpt4 book ai didi

jsf-2 - javax.el.PropertyNotFoundException :/index. xhtml @19,67 值 ="#{credentials.username}": Target Unreachable, 标识符 'credentials' 解析为空

转载 作者:行者123 更新时间:2023-12-04 04:40:39 27 4
gpt4 key购买 nike

我是 JSF 及其同事的新手。

我的开发环境如下
java 6
Tomcat 6
eclipse
Primeface 2.5

我正在尝试使用 Instant primefaces starter 中描述的测试 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"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
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>PrimeFaces Web Application</display-name>

<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>

<!-- Welcome page -->
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

人脸配置文件
<?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_1.xsd"
version="2.1">

bean.xml

是一个空文件

索引.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:p="http://primefaces.org/ui">
<h:head />
<body>
<ui:composition template="/WEB-INF/templates/main.xhtml">
<ui:define name="title">Welcome to our site</ui:define>
<ui:define name="content">
<h:form>
<h:panelGrid columns="2" border="0">
<p:panel header="Please Sign In">
<p:panelGrid columns="2" styleClass="no-border"
columnClasses="no-border,no-border">
<p:outputLabel value="Username" for="username" />
<p:inputText id="username" label="Username"
value="#{credentials.username}" />
<p:outputLabel value="Password" for="password" />
<p:password id="password" label="Password"
value="#{credentials.password}" />
<h:outputText value="" />
<p:commandLink value="Forgot your password?" />
<h:outputText value="" />
<p:commandButton value="Login" action="members"
actionListener="#{loginController.login}" />
<h:outputText value="" />
</p:panelGrid>
</p:panel>
<ul>
<li>Find out what's happening</li>
<li>Rate and review shows</li>
<li>Invite your friends</li>
<li><a href="/faces/register.xhtml">Join today!</a>
</li>
</ul>
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>

登录 Controller .java
package com.example.starterexample.controller;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;

import com.example.starterexample.model.Credentials;

/**
* Controller class for desktop and mobile login functionality.
*
* @uml.dependency supplier="com.mycompany.controller.AbstractController"
*/
@ManagedBean(name="loginController", eager=true)
//@ViewScoped
@RequestScoped
/*
* @ViewScoped means the object is created by JSF
* and its lifecycle is scoped to the current view.
* Once the user navigates to another view, the LoginControllerobject is released and
* will eventually be garbage-collected by the JVM
*/
public class LoginController extends AbstractController {

private static final long serialVersionUID = -6710063228036238737L;

@ManagedProperty(value = "#{credentials}")
private Credentials credentials;

public String login() {
String outcome = null;
try {
String username = credentials.getUsername();
String password = credentials.getPassword();
//User user = userService.findUser(username, password);
//if (user == null) {
// addErrorMessage("Invalid login");
// userSession.setUser(null);
//} else {
// userSession.setUser(user);
// if (!activeUsers.contains(user)) {
// activeUsers.add(user);
// }
//outcome = "members";
//}

addErrorMessage("Invalid login");
} catch (Exception e) {
logger.error("Unable to login:", e);
}
return outcome;
}

public void setCredentials(Credentials credentials) {
this.credentials = credentials;
}


}

凭证.java
package com.example.starterexample.model;

import javax.enterprise.inject.Model;

@Model
public class Credentials {

private String username;
private String password;

public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}


}

错误:
Sep 21, 2013 5:03:34 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute
WARNING: /index.xhtml @19,67 value="#{credentials.username}": Target Unreachable, identifier 'credentials' resolved to null
javax.el.PropertyNotFoundException: /index.xhtml @19,67 value="#{credentials.username}": Target Unreachable, identifier 'credentials' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at org.primefaces.renderkit.InputRenderer.findImplicitConverter(InputRenderer.java:170)
at org.primefaces.renderkit.InputRenderer.findConverter(InputRenderer.java:190)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:196)
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.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at org.primefaces.component.panel.Panel.processValidators(Panel.java:297)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
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 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)

请帮我找到我错过了什么。

我一直在寻找类似的问题,但对我没有任何帮助。

我检查了创建的war文件,并且在WEB-INF/classes中找到了类文件

提前致谢。

最佳答案

我也用这个例子进行自学等。实际上我和你遇到了同样的问题。此示例有错误,因此您不应盲目使用它。此 article帮助我更好地理解 bean 类型(CDI、EJB、JSF bean)并编写可行的代码。

您不应将 JSF 托管 bean 与 CDI 一起使用。 CDI bean 本身更强大。
这对我有用。

LoginController 开始像

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;


@Named
@javax.faces.view.ViewScoped
public class LoginController extends AbstractController {


private static final long serialVersionUID = -6710063228036238737L;


@Inject
private ActiveUsers activeUsers;

@Inject
private Credentials credentials;

@Inject
private UserService userService;

....
}

ActiveUsers 看起来像
import java.util.ArrayList;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

@Named("activeUsers")
@ApplicationScoped
public class ActiveUsers extends ArrayList<User> {

private static final long serialVersionUID = -3068333669859836249L;

}

凭据:
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named("credentials")
@RequestScoped
public class Credentials {

private String password;

private String username;

public String getPassword() {
return password;
}

public String getUsername() {
return username;
}

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

public void setUsername(String username) {
this.username = username;
}

}

希望这会帮助你

关于jsf-2 - javax.el.PropertyNotFoundException :/index. xhtml @19,67 值 ="#{credentials.username}": Target Unreachable, 标识符 'credentials' 解析为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18932971/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com