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 includebody
, 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.
This
<script>
is rendered immediately before the closing </body>
tag because target=body
. The benefit of rendering scripts before the closing </body>
tag is that they do not block rendering of the rest of the page.
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 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20