Tuesday, 16 October 2012

include JavaScript file in JSF

In JSF 2.0, you can use <h:outputScript /> tag in the <h:head> section to render a HTML “script” element, and link it to a js file. For example,

<h:outputScript library="js" name="common.js" />

It will generate following HTML output

<script type="text/javascript" 
   src="/JavaServerFaces/faces/javax.faces.resource/common.js?ln=js">
</script>

The directory hierarchy is as below.

No comments:

Post a Comment