I want to include a js file in my jsf page. i tried the usual way of doing it but it didnt work.
<script language="Javascript" type="text/javascript" src="js/alertMessages.js"></script>
I also tried the adf components as below: but there is no af:resource component in my adf lib.
<af:document>
<f:facet name="metaContainer">
<af:resource source="/mySourceDirectory"/>
</facet>
<af:form></af:form>
</af:document>
Please let me know how do i include the js file in my page.
Thanks…
Relative resource URLs (the URLs of
<script>,<link>,<img>and<a>elements which do not start with schemehttp://or slash/) are relative to the current request URL (as you see in browser address bar).So if you’re for example opening the page by
then the script file as you have there will actually be downloaded from
instead of
You would like to make the URL relative to the domain root instead. So it must become
/contextname/js/alertMessages.js. You can use${pageContext.request.contextPath}to inline the context path dynamically:Note that the
languageattribute is superfluous. Also please note that for JSF 2.x there are tags available which do that implicitly like<h:outputScript>.See also: