Skip to main content

Suffix mapping causing .xhtml to be appended to resources served with h: tags

No replies
oversteer
Offline
Joined: 2011-03-28
Points: 0

<servlet-name>FacesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>FacesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Immediately after the change I noticed that static resources such as javascript, css & image files served
using h:outputScript, h:outputStylesheet & h:graphicImage tags all had .xhtml appended to them. So I'd
have <h:outputScript name="jquery.js"> and the page source rendered to the browser would be
<script type="text/javascript" src="/context-root/javax.faces.resource/jquery.js.xhtml"/>. Despite this
apparent disconnect the resource is served successfully.
The problem is that in the application I want to set real *.xhtml files to no-cache, and cache real static
resources. With this phantom .xhtml append problem everything is getting treated as an xhtml file and set
to no-cache.
I just reproduced this in a netbeans shell web project so it's either something setup incorrectly in my
glassfish 3.1.1 server configuration, although this seems unlikely, or it works like this for everyone.
I logged this jira in july last year http://java.net/jira/browse/JAVASERVERFACES-2153 but now we're system
testing and I've got to find a resolution, even if this is to revert to prefix mapping.
Has anyone got any ideas why this might be happening, what I can do to resolve the problem? One thing
I should mention is that I don't have a problem using standard html tags, so if I use <img src="/context-root/
resources/myimage.png" everything works as it should do, and the same for script and link href
tags. In the example below, both lines render html that will cause the server to render the test.css file. In
the first case the page source has the reference test.css.xhtml, in the second test.css. If I replace "resources"
with "javax.faces.resource" in the link href tag I get a 404 not found.


<h:outputStylesheet name="test.css"/>
<link href="#{request.contextPath}/resources/test.css" rel="stylesheet" type="text/css"/>

Thanks.