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 .xhtml
suffix appended to it. So main.css
becomes main.css.xhtml
when loaded in the browser. I would like to have it so the .xhtml
isn't apended to the resources (don't mind about the pages themselves).
Is there a way where we can NOT have .xhtml
appended to resources?
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?
I am using Majorra v.2.1.17 on Glassfish 3.1.2.2.
Current Faces Servlet loading as in web.xml (updated)
<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>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/javax.faces.resource/*</url-pattern>
</servlet-mapping>
Why this questions is different from others
- JSF 2 resources with CDN?. 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.
- Change /javax.faces.resource prefix of resource URLs. I don't want to change the prefix. I want only to change the suffix. I would want
<link type="text/css" rel="stylesheet" href="/javax.faces.resource/main03.css.xhtml?ln=styles">
to become :<link type="text/css" rel="stylesheet" href="/javax.faces.resource/main03.css?ln=styles">
WITHOUT the.xhtml
extension. - Changing JSF prefix to suffix mapping forces me to reapply the mapping on CSS background images. 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).
Reasoning
Sure you might be asking me why I need this. Well, we are moving our application to be served by the Akamai CDN.
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 xhtml
because this would be caching all pages as well as static content. Which by that would cause problems with sessions and such.
Attempted Solution
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.
However, I am getting an error when loading composite components. I am getting an error as such :
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)
...
Composite component is loaded correctly because if I "unregister" the new ResourceHandler
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 grepcode
this would be at this last line (975) where the error happens :
String packageName = componentResource.getLibraryName();
String className = componentResource.getResourceName();
className = packageName + '.' + className.substring(0, className.lastIndexOf('.'));
Meaning that the resourceName
, aka className
is null
since the error I am getting is java.lang.NullPointerException
. I can't seem to figure out how/where the ResourceHandler
is called vis-a-vis a composite component. Any help figuring out this last issue?
background: #14311b url("#{resource['templateImages:background.jpg']}") no-repeat 0 0;
not working, since jsf wouldn't be running on "non-xhtml" files. Would it then be a good idea add "*.css" as a pattern for the jsf servlet? Or simply use static fetching? What about resources located inln=javax.faces
? – Bumkin/javax.faces.resource/*
to faces servlet mapping. – Leewardhttp://localhost:8080/myApp/javax.faces.resource/main03.css?ln=styles
. This does not work, buthttp://localhost:8080/myApp/javax.faces.resource/main03.css.xhtml?ln=styles
does. I know I am missing something. – Bumkin/javax.faces.resource/*
is added to servlet mapping. But now going to :javax.faces.resource/resources/styles/main03.css
to access this sheet, the stylesheet is still not being processed by jsf – Bumkin