Mr Asker Mr Asker - 5 months ago 56
Java Question

Servlet.service() for servlet [Faces Servlet] in context with path [/hello] threw exception

When I run the code in the student_form.xhtml I am getting the error underneath. I do not know why the error is partly in english and german. in the student_form.xhtml the following warning

Unknown tag (f:selectItem).
is being displayed.


Servlet.service() for servlet [Faces Servlet] in context with path [/hello] threw exception


student_form.xhtml

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough">

<h:head>
<title>Student Registration Form</title>
</h:head>
<h:body>

<h:form>
<!-- JSF will call student.setName(string firstName) -->
First name: <h:inputText id="firstName"
value="#{student.firstName}" />
<br />
<br />

Last name: <h:inputText id="lastName"
value="#{student.lastName}" />

<br />
<br />

Country:
<h:selectOneMenu value="#{student.country}">
<f:selectItem itemvalue="Brazil" itemLabel="Brazil" />
<f:selectItem itemvalue="France" itemLabel="France" />
<f:selectItem itemvalue="Germany" itemLabel="Germany" />
<f:selectItem itemvalue="India" itemLabel="India" />
<f:selectItem itemvalue="Turkey" itemLabel="Turkey" />
<f:selectItem itemvalue="United kingdom" itemLabel="United kingdom" />
<f:selectItem itemvalue="United States" itemLabel="United States" />
</h:selectOneMenu>



<br />
<br />


<h:commandButton value="Submit" action="student_response" />
</h:form>

</h:body>
</html>


student_response.xhtml

<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head>
<title>Student Confirmation</title>
</h:head>
<h:body>
<!-- JSF will call student.getFirstName() -->

The student is confirmed: #{student.firstName} #{student.lastName}

<br/> <br/>

The student's country: #{student.country}

</h:body>
</html>


Student class

package com.stack;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Student {
private String firstName;
private String lastName;
private String country;

public Student(){

}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

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

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}


}


error

Jun 19, 2016 7:40:41 PM org.apache.catalina.core.StandardWrapperValve invoke
SCHWERWIEGEND: Servlet.service() for servlet [Faces Servlet] in context with path [/hello] threw exception [Error Parsing /student_form.xhtml: Error Traced[line: 26] Präfix "f" für Element "f:selectItem" ist nicht gebunden.] with root cause
javax.faces.view.facelets.FaceletException: Error Parsing /student_form.xhtml: Error Traced[line: 26] Präfix "f" für Element "f:selectItem" ist nicht gebunden.
at com.sun.faces.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:444)
at com.sun.faces.facelets.compiler.SAXCompiler.doMetadataCompile(SAXCompiler.java:427)
at com.sun.faces.facelets.compiler.Compiler.metadataCompile(Compiler.java:130)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.createMetadataFacelet(DefaultFaceletFactory.java:499)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.access$200(DefaultFaceletFactory.java:106)
at com.sun.faces.facelets.impl.DefaultFaceletFactory$2.newInstance(DefaultFaceletFactory.java:209)
at com.sun.faces.facelets.impl.DefaultFaceletFactory$2.newInstance(DefaultFaceletFactory.java:207)
at com.sun.faces.facelets.impl.DefaultFaceletCache$2.newInstance(DefaultFaceletCache.java:97)
at com.sun.faces.facelets.impl.DefaultFaceletCache$2.newInstance(DefaultFaceletCache.java:92)
at com.sun.faces.util.ExpiringConcurrentCache$1.call(ExpiringConcurrentCache.java:99)
at java.util.concurrent.FutureTask.run(Unknown Source)
at com.sun.faces.util.ExpiringConcurrentCache.get(ExpiringConcurrentCache.java:114)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getViewMetadataFacelet(DefaultFaceletCache.java:146)
at com.sun.faces.facelets.impl.DefaultFaceletCache.getViewMetadataFacelet(DefaultFaceletCache.java:63)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:320)
at com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:250)
at com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:113)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:241)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:121)
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:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

Answer

try to add xmlns:f="http://java.sun.com/jsf/core" in your html tag

<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://java.sun.com/jsf/core" >