If your sole purpose is to serve it "the Richfaces way" (it's actually the JSF 2.0 way), then use <h:outputScript>
. Put the file in /resources/js/ajax-error.js
of public webcontent (the main path /resources
is mandatory and its name cannot be changed). Then reference it as follows:
<h:outputScript name="js/ajax-error.js" />
Regardless of its location in the template, it'll be generated into the HTML <head>
like follows assuming that your FacesServlet
is mapped on *.jsf
:
<script type="text/javascript" src="/contextname/javax.faces.resource/js/ajax-error.js.jsf"></script>
But that doesn't offer you EL support! You won't be able to use #{}
in that script. Only in stylesheets which are included by <h:outputStylesheet>
the #{}
is supported in order to locate background images the JSF 2.0 #{resource['logo.png']}
way, but nothing more than that.
In your particular case, I'd rather reference #{facesContext.externalContext.requestContextPath}
(or its shorter and more popular counterpart #{request.contextPath}
) in the HTML <base>
tag or some global JS variable or the HTML data
attribute. If set as <base>
, all relative links will be relative to it, also in JS.
See also: