-1

I am getting an Exception while updating an element on submitting the the value in textbox and clicking the button,which should update another element of Id display,But instead throwing exception. I understand the exception but still not able to figure how should i resolve it.

MY pom.xml file :

****<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;  
}  
} 

Exception I am getting

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)


I am not able to identify why commandButton is not able to update the element of the Id mentioned above.Though its very basic but still need clarification , why its not updating the Element Thanks in advance

BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
  • I checked it again, all things looks good, Can any of you try to compile and run this code? – Rajat Dobriyal Dec 12 '19 at 13:27
  • @BalusC You're right I'm sorry for this wrong information. I thought I've had the same issue but mine was different. – Mihawk Dec 12 '19 at 13:42
  • I guess I tried everything, But this code seems to fine , It's failing somewhere else. – Rajat Dobriyal Dec 12 '19 at 13:49
  • @BalusC did you got a chance to run the above code? Or found any thing? I am stuck due to this. – Rajat Dobriyal Dec 13 '19 at 07:01
  • You're using the latest PrimeFaces but noy using the latest Mojarra. 2.1.7 is from Feb 2012 .. The latest is [2.3.14](https://mvnrepository.com/artifact/org.glassfish/jakarta.faces) from Oct 2019 (single JAR). Give it a try and always keep your deps up to date. – BalusC Dec 13 '19 at 09:30
  • Mojarra and PrimeFaces are two diff things? Why i need to include Mojarra to run this code? – Rajat Dobriyal Dec 13 '19 at 10:02
  • Mojarra is an implementation of JSF (just like MyFaces is). PrimeFaces is a component library that provides rich components for the JSF framework. – Steven De Groote Dec 14 '19 at 22:33
  • @StevenDeGroote The above mentioned code does not require Mojarra dependency to run. So just let me know what is the reason i am getting this error. – Rajat Dobriyal Dec 16 '19 at 06:47
  • Your used "jsf-impl" dependency IS mojarra ;) But as @BalusC said, try upgrading it, and see if you continue to have this problem. – Steven De Groote Dec 16 '19 at 08:49
  • @StevenDeGroote, Sorry here i was not aware that these impl classes belong to Mojarra, I thought these are just impl classes. And after upgrading my packages the issue got resolved. Thank you everyone out here. – Rajat Dobriyal Dec 16 '19 at 10:03
  • 1
    Yup. Mojarra is core JSF (all tags from `http://xmlns.jcp.org/jsf/*` namespace). You cannot run JSF without a core JSF impl (there are currently two available: Mojarra and MyFaces, and you're currently using Mojarra). PrimeFaces is just a JSF extension (all tags from `http://primefaces.org/*` namespace). And you're using Mojarra 2.1.7 which is prehistoric. You need to remove the two `com.sun.faces:*` dependencies of it and replace it by newest one available which is 2.3.14 from `org.glassfish:jakarta.faces`. – BalusC Dec 16 '19 at 10:03

1 Answers1

0

You're using JSF 2.2 XHTML namespaces with http://xmlns.jcp.org domain in your XHTML page, but you're with Mojarra 2.1.7 actually using a JSF 2.1 implementation of almost 8 years old. The JSF 2.2 namespaces are only supported in a JSF 2.2 or newer implementation. In effects, your <h:outputText> is actually not executed, but interpreted as plain template text.

If you remove update="display" from your PrimeFaces <p:ajax> tag, then the page would have loaded fine, but when you inspect the generated HTML source, then you would still have seen all core JSF tags unparsed there. That explains the problem of your PrimeFaces <p:ajax> tag. It indeed really couldn't find the component, because the <h:xxx> namespace was not correctly recognized.

You could fix it by downgrading from http://xmlns.jcp.org to http://java.sun.com domain, but this is not recommended. Best is to just keep your libraries up to date. These days you can find Mojarra in org.glassfish:jakarta.faces group which is currently (Dec 2019) at 2.3.14.

Replace

<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>

by

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

and you're good to go.

See also:

Community
  • 1
  • 1
BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513