JSF中的Javascript-没有库,没有名称,没有正文内容的outputScript [英] Javascript in JSF - outputScript with no library, no name, and no body content
问题描述
我想在jsf/primefaces项目中实现pacman游戏.
I want to implement a pacman game in an jsf/primefaces project.
可以在此处找到游戏.
这是我的jsf页面:
<!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"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Screen</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="" />
<style type="text/css">
@font-face {
font-family: 'BDCartoonShoutRegular';
src: url('BD_Cartoon_Shout-webfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
#pacman {
height: 450px;
width: 342px;
margin: 20px auto;
}
#shim {
font-family: BDCartoonShoutRegular;
position: absolute;
visibility: hidden
}
h1 {
font-family: BDCartoonShoutRegular;
text-align: center;
}
body {
width: 342px;
margin: 0px auto;
font-family: sans-serif;
}
a {
text-decoration: none;
}
</style>
</h:head>
<h:body>
<div id="shim">shim for font face</div>
<h1>HTML5 Pacman</h1>
<a href="http://arandomurl.com/">Writeup</a> |
Code on <a href="http://arandomurl.com/">Github</a>
<div id="pacman"></div>
<h:outputScript src="../pacman.js"/>
<h:outputScript src="../modernizr-1.5.min.js"/>
<script>
// <![CDATA[
var el = document.getElementById("pacman");
if (Modernizr.canvas && Modernizr.localstorage &&
Modernizr.audio && (Modernizr.audio.ogg || Modernizr.audio.mp3)) {
window.setTimeout(function () { PACMAN.init(el, "./"); }, 0);
} else {
el.innerHTML = "Sorry, needs a decent browser<br /><small>" +
"(firefox 3.6+, Chrome 4+, Opera 10+ and Safari 4+)</small>";
}
// ]]>
</script>
</h:body>
</html>
页面上没有异常.但是,当我加载页面时,它看起来像这样:
I get no exceptions in my page. However, when I load the page it looks like that:
如您所见,游戏没有添加!
as you can see the game does not gets added!
有什么解决办法吗?
更新
当我这样做:
<script src="pacman.js"></script>
<script src="modernizr-1.5.min.js"></script>
我也没有输出... 更新
I also get no output... UPDATE
我的文件夹结构:
推荐答案
<h:outputScript>
标记只能用于从resources
文件夹加载脚本.
如果要从resources
文件夹之外的其他文件夹加载,请使用以下代码:
The <h:outputScript>
tag can be used to load script from resources
folder only.
If you wish to load from other folder outside resources
folder, use this code:
<script type="text/javascript" src="#{request.contextPath}/path/to/js"></script>
其中,request.contextPath
是站点的上下文路径(例如:/pacman).
例子:
如果您的js文件位于以下路径中:/waitingScreen/audio/pacman.js
相应的代码:
where request.contextPath
is the context path of your site (for example: /pacman).
Example:
if your js file is in this path: /waitingScreen/audio/pacman.js
corresponding code:
<script type="text/javascript" src="#{request.contextPath}/waitingScreen/audio/pacman.js"></script>
(request.contextPath已由JSF定义,您可以使用它)
(request.contextPath is already defined by JSF, you could use it)
<h:outputScript>
标记还可用于从primeFaces加载现有脚本和资源,例如,加载jquery:
The <h:outputScript>
tag is also useful to load existing script and resources from primeFaces, example, to load jquery:
<h:outputScript library="primefaces" name="jquery/jquery.js" />
("library
"属性表示资源文件夹中文件夹的路径)
(The library
attribute in meaning of the path of a folder in resources folder)
这篇关于JSF中的Javascript-没有库,没有名称,没有正文内容的outputScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!