h:outputScript

HtmlOutputScript is a UIOutput component that renders a <script> element with type="text/javascript".

Resource Usage

A JavaScript resource can be added to the page by specifying the library and name attributes.

Source Code

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

	<!-- This script calls a JavaScript function that is defined in the external JavaScript -->
	<!-- resource named example.js -->
	<span id="example:text"></span>
	<h:outputScript>
		exampleNamespace.exampleFunction('example:text');
	</h:outputScript>
	<h:outputScript library="js" name="example.js" target="head" />

</ui:composition>
var exampleNamespace = {
	exampleFunction : function(id) {
		document.getElementById(id).innerHTML = 'A script has called <code>exampleNamespace.exampleFunction(id)</code> '
				+ 'which resides in the JavaScript resouce file named <code>example.js</code>.';
	}
};
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20