PrimeFaces <p:commandButton>无法更新<h:outputText>并抛出org.primefaces.expression.ComponentNotFoundException:

时间:2019-12-12 12:49:59

标签: jsf primefaces

当在文本框中提交值并单击按钮时更新元素时​​,我得到了异常,这应该更新Id显示的另一个元素,但引发异常。 我了解该异常,但仍然无法确定应该如何解决。

MY pom.xml文件:

****<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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jsftesting</groupId>
<artifactId>jsf</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>jsf Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.1.7</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>7.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.1.7</version>
    </dependency>
</dependencies>
<build>
    <finalName>jsf</finalName>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.1</version>

            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

home.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:h="http://xmlns.jcp.org/jsf/html"  
    xmlns:p="http://primefaces.org/ui">  
    <h:head>  
    <title>Ajax Basic Example</title>  
    </h:head>  
    <h:body>  
    <h2>Basic Ajax Example</h2>  
    <h:form>  
<h:panelGrid columns="4" cellpadding="5">  
<h:outputLabel for="name" value="Name:" style="font-weight:bold" />  
<p:inputText id="name" value="#{user.name}" />  
<p:commandButton value="Submit" update="display" icon="ui-icon-check" />  
<h:outputText id="display" value="#{user.name}" />  
</h:panelGrid>  
</h:form>  
</h:body>  
</html>

User.java

import java.io.Serializable;  
import javax.faces.bean.ManagedBean;  
@ManagedBean(name = "user" ,eager=true)  
public class User implements Serializable{  
String name;  
String lastName;  
public String getName() {  
return name;  
}  
public void setName(String name) {  
this.name = name;  
}     

public String getLastName() {  
return lastName;  
}  
public void setLastName(String lastName) {  
this.lastName = lastName;  
}  
} 

我遇到的异常

SEVERE: Error Rendering View[/views/home.xhtml]
org.primefaces.expression.ComponentNotFoundException: Cannot find component for expression "display" referenced from "j_idt4".
    at org.primefaces.expression.SearchExpressionFacade.cannotFindComponent(SearchExpressionFacade.java:720)
    at org.primefaces.expression.SearchExpressionFacade.resolveClientIds(SearchExpressionFacade.java:259)
    at org.primefaces.util.AjaxRequestBuilder.addExpressions(AjaxRequestBuilder.java:136)
    at org.primefaces.util.AjaxRequestBuilder.update(AjaxRequestBuilder.java:129)
    at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:412)
    at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:399)
    at org.primefaces.component.commandbutton.CommandButtonRenderer.buildRequest(CommandButtonRenderer.java:145)
    at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeMarkup(CommandButtonRenderer.java:78)
    at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeEnd(CommandButtonRenderer.java:63)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:526)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:367)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1591)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.base/java.lang.Thread.run(Unknown Source)


我无法确定为什么commandButton无法更新上述ID的元素。尽管它非常基本,但仍需要澄清,但为什么不更新Element 预先感谢

1 个答案:

答案 0 :(得分:0)

您在XHTML页面中使用具有http://xmlns.jcp.org域的JSF 2.2 XHTML命名空间,但实际上在Mojarra 2.1.7中使用了将近8年的JSF 2.1实现。仅在JSF 2.2或更高版本的实现中支持JSF 2.2命名空间。实际上,您的<h:outputText>实际上并未执行,而是解释为纯模板文本。

如果从PrimeFaces update="display"标记中删除<p:ajax>,则该页面将正常加载,但是当您检查生成的HTML源代码时,您仍将看到所有未解析的核心JSF标记。这就解释了您的PrimeFaces <p:ajax>标签的问题。确实确实找不到该组件,因为<h:xxx>命名空间未正确识别。

您可以通过将域从http://xmlns.jcp.org降级为http://java.sun.com来解决此问题,但是不建议这样做。最好是仅使您的库保持最新。这些天,您可以在org.glassfish:jakarta.faces组中找到Mojarra,该组当前(2019年12月)的版本为2.3.14。

替换

<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1.7</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.1.7</version>
</dependency>

作者

<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>jakarta.faces</artifactId>
    <version>2.3.14</version>
</dependency>

你很高兴。

另请参见: