我一直在按照 this 教程在 Windows 10 上的 Wildfly-21.0 服务器上使用 JAVA-14 和 Maven 在 Eclipse 版本 2020-09 (4.17.0) 上设置 JSF。完成页面上的说明后,我可以浏览到我的 index.xhtml 页面,但是当我提交表单时我无法访问支持 bean。我收到以下错误:
[javax.enterprise.resource.webcontainer.jsf.context] (default task-1) javax.el.PropertyNotFoundException: /index.xhtml @14,61 value="#{bean.input}": Target Unreachable, identifier 'bean' resolved to null: javax.el.PropertyNotFoundException: /index.xhtml @14,61 value="#{bean.input}": Target Unreachable, identifier 'bean' resolved to null
at [email protected]//com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:64)
at [email protected]//com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:71)
at [email protected]//javax.faces.component.UIInput.getConvertedValue(UIInput.java:1110)
at [email protected]//javax.faces.component.UIInput.validate(UIInput.java:1011)
at [email protected]//javax.faces.component.UIInput.executeValidate(UIInput.java:1322)
at [email protected]//javax.faces.component.UIInput.processValidators(UIInput.java:733)
at [email protected]//javax.faces.component.UIForm.processValidators(UIForm.java:229)
at [email protected]//com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:608)
at [email protected]//com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:159)
at [email protected]//javax.faces.component.UIComponent.visitTree(UIComponent.java:1456)
at [email protected]//javax.faces.component.UIForm.visitTree(UIForm.java:355)
at [email protected]//javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at [email protected]//javax.faces.component.UIComponent.visitTree(UIComponent.java:1468)
at [email protected]//com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:400)
at [email protected]//com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:261)
at [email protected]//javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1308)
at [email protected]//com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:53)
at [email protected]//com.sun.faces.lifecycle.Phase.doPhase(Phase.java:76)
at [email protected]//com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:177)
at [email protected]//javax.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:707)
at [email protected]//javax.faces.webapp.FacesServlet.service(FacesServlet.java:451)
at [email protected]//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
at io.opentracing.contrib.opentracing-jaxrs2//io.opentracing.contrib.jaxrs2.server.SpanFinishingFilter.doFilter(SpanFinishingFilter.java:52)
at [email protected]//io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
at [email protected]//io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
at [email protected]//io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
at [email protected]//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at [email protected]//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at [email protected]//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at [email protected]//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
at [email protected]//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:132)
at [email protected]//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at [email protected]//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at [email protected]//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at [email protected]//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at [email protected]//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at [email protected]//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at [email protected]//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
at [email protected]//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at [email protected]//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at [email protected]//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
at [email protected]//io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
at [email protected]//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
at [email protected]//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at [email protected]//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'bean' resolved to null
at [email protected]//com.sun.el.parser.AstValue.getTarget(AstValue.java:148)
at [email protected]//com.sun.el.parser.AstValue.getType(AstValue.java:62)
at [email protected]//com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:160)
at [email protected]//org.jboss.weld.module.web.el.WeldValueExpression.getType(WeldValueExpression.java:93)
at [email protected]//org.jboss.weld.module.web.el.WeldValueExpression.getType(WeldValueExpression.java:93)
at [email protected]//com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
... 70 more
在 Eclipse 我的项目属性中,“Project Facets”我无法将 JavaServer Faces 版本设置为 2.3,因为我收到“无法将项目 Facet JavaServer Faces 版本更改为 2.3”。所以我选择了2.2版本。根据 this 堆栈溢出帖子,我的 CDI 实现可能有问题。
关于如何解决此问题并继续前进有什么建议吗?
提前致谢!
我的POM文件:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tanvir.project</groupId>
<artifactId>SudokuSolver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Sudoku Solver</name>
<description>Webapp for solving sudoku puzzles</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
我的WEB-INF/beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_1.xsd"
version="1.1" bean-discovery-mode="all">
</beans>
我的WEB-INF/faces-config.xml:
<?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">
<!-- JSF configuration here. -->
</faces-config>
我的支持豆:
package tanvir.project.sudoku;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
@Named
@RequestScoped
public class Bean {
private String input;
private String output;
public void submit() {
output = "Hello World! You have typed: " + input;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getOutput() {
return output;
}
}
最后是我的xhtml文件:
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
>
<h:head>
<title>Hello World</title>
</h:head>
<h:body>
<h1>Hello World</h1>
<h:form>
<h:outputLabel for="input" value="Input" />
<h:inputText id="input" value="#{bean.input}" />
<h:commandButton value="Submit" action="#{bean.submit}">
<f:ajax execute="@form" render=":output" />
</h:commandButton>
</h:form>
<h:outputText id="output" value="#{bean.output}" />
</h:body>
</html>
我没有像教程中提到的那样使用 jakarta.jakartaee-api 版本 8.0.0,而是使用版本 9.0.0。这需要我在 Bean.java 中导入 jakarta.inject.Named 而不是 javax.inject.Named 来使用 @Named 注释。当我在 POM 文件中将 jakarta.jakartaee-api 版本设置为 8.0.0 时,问题得到解决(现在可以使用 EL 语句引用支持 bean)。
我目前面临将 JSF 2.2 Maven Web 应用程序从 JDK 8 迁移到 Java 11 的挑战。我的目标是维持 Javax 包的使用,而不重构到 Jakarta。
解决了几个构建和部署问题后,该应用程序成功部署在WildFly 19上。但是,在第一次交互时,我遇到了以下错误:
引起:javax.el.PropertyNotFoundException:目标无法访问,标识符“XXXMBean”解析为 null 在 [电子邮件受保护]//com.sun.el.parser.AstValue.getTarget(AstValue.java:148) 在 [电子邮件受保护]//com.sun.el.parser.AstValue.getType(AstValue.java:62) 在 [电子邮件受保护]//com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:160) 在 [电子邮件受保护]//org.jboss.weld.module.web.el.WeldValueExpression.getType(WeldValueExpression.java:93)
鉴于此背景,我有两个问题:
感谢您的任何见解!