【发布时间】:2011-05-10 18:55:59
【问题描述】:
我有一个关于将 jquery 库与 JSF 2.0 集成的问题
当使用 <h:outputScript library="/common/js" name="jquery-1.5.1.min.js" target="head" /> 时,我应该在我的 xhtml 文件中也包含 <h:head> 标记。所以脚本在头部呈现。
但我有一个包含 <h:head>,<h:body> 部分的 template.xhtml。我如何为从该模板派生的页面创建target="head" /> ui:composition="template.xhtml"?
target=form> 也不起作用。
我的模板:
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><h:outputText value="#{msg['label.titlemsg']}" /></title>
<h:outputStylesheet library="css" name="style.css" target="head"/>
</h:head>
<h:body>
<f:view locale="#{localeBean.locale}">
<div id="outer">
<div id="container">
<div id="inner">
<div class="float">
<div class="main">
<!-- -->
<div id="icerik">
<ui:insert name="icerik">
</ui:insert>
</div></div></div></div></div></div>
<div id="langbar" align="center">
</div>
</f:view>
</h:body>
</html>
所以我有“icerik”。
在我的文件中:
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/Template.xhtml">
<ui:define name="icerik">
<h:outputScript library="/common/js" name="jquery-1.5.1.min.js" target="head" />
<h:outputScript library="/common/js" name="jquery.validate.js" target="head" />
</ui:define>
</ui:composition>
</html>
【问题讨论】:
-
它应该这样工作。相反会发生什么?当您在 webbrowser 中右键单击页面并查看 JSF 生成的 HTML 输出时,您会看到什么?想要的
<script>在那里吗? -
嗨,我使用模板,所以 target=head 和 target=body 不会生成关于 .js 文件的输出。
-
嗨,我用一些代码更新了我的问题。
-
您能更清楚地了解会发生什么吗?您在生成的 HTML 输出的头部看到 nothing 了吗?甚至没有
<script type="text/javascript" src="RES_NOT_FOUND">? -
是的,不使用模板我的 .js 文件可以在 head 标签中看到。使用模板对我来说会导致这个问题。如果使用 ui:define,则头部不显示任何内容