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.
A script has called exampleNamespace.exampleFunction(id) which resides in the JavaScript resouce file named example.js.

Source Code

  1. <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html"
  2. xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
  3.  
  4. <!-- This script calls a JavaScript function that is defined in the external JavaScript -->
  5. <!-- resource named example.js -->
  6. <span id="example:text"></span>
  7. <h:outputScript>
  8. exampleNamespace.exampleFunction('example:text');
  9. </h:outputScript>
  10. <h:outputScript library="js" name="example.js" target="head" />
  11.  
  12. </ui:composition>
  1. var exampleNamespace = {
  2. exampleFunction : function(id) {
  3. document.getElementById(id).innerHTML = 'A script has called <code>exampleNamespace.exampleFunction(id)</code> '
  4. + 'which resides in the JavaScript resouce file named <code>example.js</code>.';
  5. }
  6. };
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20