How to include JavaScript file in JSF
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
``
<h1>JSF 2 outputScript example</h1>
<h:outputScript library="js" name="common.js" />
</h:body>
```
It will generate following HTML output
```
<h1>JSF 2 outputScript example</h1>
<script type="text/javascript"
src="/JavaServerFaces/faces/javax.faces.resource/common.js?ln=js">
</script>
```
The JS file will render in where JSF `` 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>
How to include JavaScript file in JSF的更多相关文章
- 使用 JavaScript File API 实现文件上传
概述 以往对于基于浏览器的应用而言,访问本地文件都是一件头疼的事情.虽然伴随着 Web 2.0 应用技术的不断发展,JavaScript 正在扮演越来越重要的角色,但是出于安全性的考虑,JavaScr ...
- ResolveUrl in external JavaScript file in asp.net project
https://stackoverflow.com/questions/11263425/page-resolveurl-is-not-working-in-javascript The proble ...
- Inline Workers--Web workers without a separate Javascript file
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> </head&g ...
- Minify or format javascript file by web or notepad++
Notepad++ plugin manager install 'JSTOOL' http://tool.oschina.net/codeformat/js https://www.cnblogs. ...
- This seems to be a pre-built javascript file. webpack报这个警告怎么办?
增加 module.noParse 进行解决 例如: { resolve: { alias: { 'react': 'my/react/path' } }, module: { noParse: [/ ...
- dynamic load javascript file.
$.ajax({ url : ("js/public/" + window.localStorage.getItem("lang") + ".js&q ...
- Dynamically loading an external JavaScript or CSS file
原文: Dynamically loading an external JavaScript or CSS file 通过javascript动态加载css文件和javascript文件,主要是通 ...
- html中#include file的使用方法
有两个文件a.htm和b.htm,在同一文件夹下a.htm内容例如以下 <!-- #include file="b.htm" --> b.htm内容例如以下 今天:雨 ...
- html 中 #include file 的用法
有两个文件a.htm和b.htm,在同一目录下a.htm内容如下 <!-- #include file="b.htm" --> b.htm内容如下 今天:雨 31 ℃- ...
随机推荐
- VS2005控制台程序修改nb0文件
VS2005控制台程序修改nb0文件 我们要实现的功能就是通过CMD传递进来的值来在nb0文件末尾增加版本信息,新建控制台程序,自动生成的main函数如下,默认的代码非常简单: int _tmain( ...
- shell/bash 让vi/vim显示空格,及tab字符
shell/bash 让vi/vim显示空格,及tab字符 Vim 可以用高亮显示空格和TAB.文件中有 TAB 键的时候,你是看不见的.要把它显示出来::set listTAB 键显示为 ^I, ...
- CRC校验码
循环冗余校验码(CRC)的基本原理是:在K位信息码后再拼接R位的校验码,整个编码长度为N位,因此,这种编码也叫(N,K)码.对于一个给定的(N,K)码,可以证明存在一个最高次幂为R的多项式G(x)(R ...
- Qt之进程间通信(TCP/IP)
简述 可以通过Qt提供的IPC使用TCP/IP,使用QtNetwork模块即可实现,TCP/IP在实现应用程序和进程内部通信或与远程进程间的通信方面非常有用. QtNetwork模块提供的类能够创建基 ...
- max-height,min-height在IE下不支持的解决方法
max-height,min-height在IE下不支持的解决方法 max-width:160px; max-height:160px; _width:expression(this.width &g ...
- android studio获取SHA1
1 打开cmd,转到路径:C:\Users\usoft\.android 2 输入命令 keytool -list -v -keystore debug.keystore 3 输入命令 android ...
- Java知识点:琐碎知识点(3)
零碎 switch(x),x只可以是enum或byte.short.char.int. 枚举在switch-case语句作为标签时必须是枚举常量的非限定名称,否则Compile Error. Enum ...
- BZOJ 3573 米特运输
语文题... 原来除了hash还可以取对数啊orz #include<iostream> #include<cstdio> #include<cstring> #i ...
- make menuconfig 出错
运行 #make menuconfig HOSTLD scripts/kconfig/mconf scripts/kconfig/mconf.o: In function `main': mconf. ...
- 在web.config里使用configSource分隔各类配置
转:http://www.yongfa365.com/Item/using-configSource-Split-Configs.html 大型项目中,可能有多个Service,也就是会有一堆配置,而 ...