I currently use mojarra javax.faces-2.2.8.jar and Apache Tomcat 6.0.26 Server.
I'm trying to add ajax behaviour to an input field(it's just for simplification).
Here is the simple facelets page(welcome.xhtml):
<?xml version="1.0" encoding="UTF-8" ?>
<!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:al = "http://xmlns.jcp.org/jsf/composite/AppearanceLibrary"
xmlns:h = "http://xmlns.jcp.org/jsf/html"
xmlns:ui = "http://xmlns.jcp.org/jsf/facelets"
xmlns:f = "http://xmlns.jcp.org/jsf/core">
<h:head/>
<h:body>
<h:form>
<h:outputLabel for = "login"
value = "login" />
<h:inputText id = "login" value = "#{authentication.submittedLogin}">
<f:ajax execute = "login" render = "out" />
</h:inputText>
<h:outputText id = "out" value = "#{authentication.submittedLogin}" />
</h:form>
</h:body>
</html>
Here is the HTML output:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head id="j_idt2"><script type="text/javascript" src="/JSFCars/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Development"></script></head><body>
<form id="j_idt4" name="j_idt4" method="post" action="/JSFCars/welcome.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt4" value="j_idt4" />
<label for="j_idt4:login">login</label><input id="j_idt4:login" type="text" name="j_idt4:login" onchange="mojarra.ab(this,event,'valueChange','j_idt4:login','j_idt4:out')" /><span id="j_idt4:out"></span><input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="o5U6o+AhXUBnlwlaf5BbfJsXNxEe0OmBn+vyQUuLH1If1Hk802YaE1PT+ACraIlE+2rJMXEMJcDEgtaxMDURnPR0EFkR0Pdln4WoUMimfPxwbiCQCQcPfL+JDsPkyx+S6SvffiRyQFmz40B/lF5qtnt+AzzGhkYyuiuokiZVnJYv4hZBVhImLwKLm28dGvVh9qfnpnjngXm8cmAdIVULAY1sn1koFC2Bv702uBK0z9I6jHzMQFdPPCpBd5b+rri7R952i9cfi/CYGdcFSCq1yZGYL0s7E5Dshgaaikr5MVdJ4pRRQbiF60hypro+ZLavymy7G2pMukJNRaMhr7SxZffK13rGuCfpBXzXwdSeXZp2tMpWBhXJZ8gk/7rYzizmMgOTssZtj1inrPAgJdMSu2CJM2Q1xMV5wQSmSpU3bSHWdGknSMH4EGZsipKf8YCr3EsOSPD9khK8hlT5AmLm/iQ0j1xRHJny/6mIPJjVPPN/nD6AXBY+9bdt+SUPEKpT4u8in5ZulcG57t/9NUq/VA==" autocomplete="off" />
</form></body>
</html>
This is my deployment descriptor:
<?xml version = "1.0" encoding = "UTF-8"?>
<web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns = "http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation = "http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id = "WebApp_ID"
version = "3.1">
<context-param>
<param-name>
javax.faces.STATE_SAVING_METHOD
</param-name>
<param-value>
client
</param-value>
</context-param>
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.localizationContext
</param-name>
<param-value>
resources.application
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<listener>
<listener-class>
com.sun.faces.config.ConfigureListener
</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/welcome.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>welcome.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Inside the browser's JavaScript console I got the message that this request http://localhost:8086/JSFCars/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Development failed with 404(Not found). And as the result when I try to invoke the input field's ajax behaviour I get the following message: Uncaught ReferenceError: mojarra is not defined.
I'm aware that I should use <h:head>
and <h:body>
, otherwise the jsf.js wasn't included in first place. I've tried several browsers and the results were the same. Also I've tried the myfaces-core-2.0.2-bin jsf implementation.
I has found very similar question here. The problem was connected with the user defined filter which rejected the js request. But I don't define any filters in the web deployment descriptor. Might there be any implicitly defined filter that blocks that request? Or are there any other ideas why something blocks that request?
Since the time I asked this question I installed "GlassFish Server Open Source Edition 4.1.2"
server and deployed the application on it(I included "javax.faces-2.2.8.jar" into project libraries,
but I think the server uses the internal "Mojarra 2.2.14" JSF implementation). As the way of testing
of the JSF implementation I tried using a template, a composite componet. <ui:composition>
, <ui:define>
tags and custom library inclusion work as needed. authentication
bean is created and perfectly initialized using faces-congig.xml
. Then after it I removed everything not related to
the question and left only welcome.xhtml
page. Again I got "404 Not found".
The solution is to remove everything connected to faces servlet from the web.xml
.
The view of the rendered welcome.xhtml
page after applying the solution