title: Prevent suffix from being added to resources when page loads
body: <p>I have a JSF2 application running and working no problem.  The issue I am having with JSF is with the resource bundle. All resources have the <code>.xhtml</code> suffix appended to it.  So <code>main.css</code> becomes <code>main.css.xhtml</code> when loaded in the browser.  I would like to have it so the <code>.xhtml</code> isn't apended to the resources (don't mind about the pages themselves).</p>
  
  <p>Is there a way where we can <strong>NOT</strong> have <code>.xhtml</code> appended to resources?</p>
  
  <p>I would ideally not have to change the internal workings of the site.  I have listed ideas below, but I have to say I don't really like these.  Hoping for a solution somewhere?</p>
  
  <p>I am using Majorra v.2.1.17 on Glassfish 3.1.2.2.</p>
  
  <h3>Current Faces Servlet loading as in web.xml (updated)</h3>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/javax.faces.resource/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <h3>Why this questions is different from others</h3>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/8067904/jsf-2-resources-with-cdn?rq=1">JSF 2 resources with CDN?</a>.  I am not looking to place my resources on a CDN, but to have my resources stay on my server but are pushed towards a CDN.</li>
  <li><a href="https://stackoverflow.com/questions/7354464/change-javax-faces-resource-prefix-of-resource-urls?rq=1">Change /javax.faces.resource prefix of resource URLs</a>.  I don't want to change the prefix.  I want only to change the suffix.  I would want <code>&lt;link type="text/css" rel="stylesheet" href="/javax.faces.resource/main03.css.xhtml?ln=styles"&gt;</code> to become : <code>&lt;link type="text/css" rel="stylesheet" href="/javax.faces.resource/main03.css?ln=styles"&gt;</code> <em>WITHOUT</em> the <code>.xhtml</code> extension.</li>
  <li><a href="https://stackoverflow.com/questions/6835499/changing-jsf-prefix-to-suffix-mapping-forces-me-to-reapply-the-mapping-on-css-ba">Changing JSF prefix to suffix mapping forces me to reapply the mapping on CSS background images</a>. Since I have no issue with loading the resources.  The site works, we are simply having a hard time differrentiating a webpage from a resource (Since we are looking at the extention alone).</li>
  </ul>
  
  <h3>Reasoning</h3>
  
  <p>Sure you might be asking me why I need this.  Well, we are moving our application to be served by the Akamai CDN.</p>
  
  <p>The issue we are having with the integration of the site is that we are trying to cache static content on the edge servers.  This is done by matching file extensions (ie: .js, .doc, .png, css, etc).  We cannot match <code>xhtml</code> because this would be caching all pages as well as static content.  Which by that would cause problems with sessions and such.</p>
  
  <h3>Attempted Solution</h3>
  
  <p>In line with the answer by BalusC, I have implemented the resource handler as suggested.  I will not rewrite code here, since it is in answer below.</p>
  
  <p>However, I am getting an error when loading composite components.  I am getting an error as such : </p>
  
  <pre><code>WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
  java.lang.NullPointerException
      at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:975)
      at com.sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.createComponent(CompositeComponentTagHandler.java:162)
      at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.createComponent(ComponentTagHandlerDelegateImpl.java:494)
      at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:169)
  ...
  </code></pre>
  
  <p>Composite component is loaded correctly because if I "unregister" the new <code>ResourceHandler</code> we just created it will load.  The stack trace leads me to believe that it is trying to find this component in a java class, instead of finding it in the resources.  According to <code>grepcode</code> this would be at this last line (975) where the error happens : </p>
  
  <pre><code>String packageName = componentResource.getLibraryName();
  String className = componentResource.getResourceName();
  className = packageName + '.' + className.substring(0, className.lastIndexOf('.'));
  </code></pre>
  
  <p>Meaning that the <code>resourceName</code>, aka <code>className</code> is <code>null</code> since the error I am getting is <code>java.lang.NullPointerException</code>.  I can't seem to figure out how/where the <code>ResourceHandler</code> is called vis-a-vis a composite component.  Any help figuring out this last issue?</p>