JSF Showcase

h:outputScript

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

General Usage

The script can be rendered in different positions on the page via the target attribute. Valid values include body, form, and head. The default value of this attribute is an empty (null) value which causes the <script> to be rendered inline (corresponding to its position in the view). Specifying body for the target attribute will cause the <script> to be rendered as close to the closing body tag as possible.

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">

	<!-- Example 1: Script rendered inline -->
	<h:form>
		<h:panelGroup >
			<span id="example1:text"></span>
		</h:panelGroup>
		<h:outputScript >
			document.getElementById('example1:text').innerHTML = '#{i18n['h-outputscript-general-script-1']}';
		</h:outputScript>
	</h:form>

	<!-- Example 2: Script rendered at the bottom of the page -->
	<span id="example2:text"></span>
	<h:outputScript target="body">
		document.getElementById('example2:text').innerHTML = '#{i18n['h-outputscript-general-script-2']}';
	</h:outputScript>

</ui:composition>
Liferay Faces Bridge Implementation 4.1.0 + Showcase Common 3.0.1 + Liferay Faces Util 3.1.0 + Mojarra 2.2.14