Insert Javascript code in JSF page

Usually you may need to insert a couple of JavaScript in your JSF page markup.
The following advice helps you do it right:

 <ui:composition ...>
    <ui:define name="body">
        <!-- your code -->
        <h:outputScript target="body">
                alert("It works!");
        <!-- your code -->

So, as you see in JSF we use h:outputScript tag with CDATA inside to workaround issues like “The content of elements must consist of well-formed character data or markup” for valid XHTML.

Thanx to