您的位置:首页 > Web前端 > JavaScript

How to include JavaScript file in JSF

2015-08-28 07:33 513 查看
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

``



"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<h1>JSF 2 outputScript example</h1>

<h:outputScript library="js" name="common.js" />

</h:body>


It will generate following HTML output


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

JSF 2 outputScript example

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


It will generate following HTML output


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

JSF 2 outputScript example

```
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: