In JSF 2.0, you can use <h:outputScript /> tag to render a HTML “script” element, and link it to a js file.
For example,
<h:outputScript library="js" name="common.js" />
It will generate following HTML output…
<script type="text/javascript"
src="/JavaServerFaces/faces/javax.faces.resource/common.js?ln=js">
</script>
JSF outputScript example
An example to show you how to use <h:outputScript /> to render a “common.js“, see figure below :

JSF file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
>
<h:head></h:head>
<h:body>
<h1>JSF 2 outputScript example</h1>
<h:outputScript library="js" name="common.js" />
</h:body>
</html>
It will generate following HTML output
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
<h1>JSF 2 outputScript example</h1>
<script type="text/javascript"
src="/JavaServerFaces/faces/javax.faces.resource/common.js?ln=js">
</script>
</body>
</html>
The JS file will render in where JSF <h:outputScript /> tag is placed.
Target Attribute
In addition, you can use “target” attribute to control where to output the js file.
- target=”head” – Display within the top of HTML head tag.
- target=”body” – Display at the end of the body tag.
- no target – Display at where the tag is placed.
For example
<h:outputScript library="js" name="common.js" target="body" />
It will generate following HTML output
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<h1>JSF 2 outputScript example</h1>
<script type="text/javascript"
src="/JavaServerFaces/faces/javax.faces.resource/common.js?ln=js">
</script>
</body>
</html>
Pingback: Get the facts()
Pingback: Marketing Australia()
Pingback: judi online poker()
Pingback: Manufactured Home Leveling()
Pingback: psychic phone readings()
Pingback: Triple Sex Toy()
Pingback: Viola Davis()
Pingback: togel hongkong online()
Pingback: Pathfinder dice()
Pingback: cyprus taxi companies()
Pingback: entzündung()
Pingback: qq domino()
Pingback: Ed Sheeran Castle On The Hill()
Pingback: TAS GUCCI()
Pingback: animal sex()
Pingback: flexi access pension drawdown annuity calculator()
Pingback: Rolande()
Pingback: Newport Beach Cryotherapy()
Pingback: fitness()