使用ui:composition时如何在页面上添加不同的javascript [英] How to add different javascripts on a page when using ui:composition
问题描述
我正在使用带有ui:composition这样的页面
I am using a page with ui:composition use on it like this
<?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"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title></title>
</h:head>
<h:body>
<ui:composition template="./WEB-INF/templates/layout.xhtml">
<ui:define name="title">#{faqAddUpdate.actionState} FAQ</ui:define>
<ui:define name="content">
<h:form id="faqAddUpdateForm" style="border-color: #000000;width: 960px;position: absolute;left: 150px;" prependId="false">
....
....
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
我的layout.xhtml看起来像这样
My layout.xhtml look like this
<?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:h="http://java.sun.com/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="textext/javascript" src="ckeditor/ckeditor.js" >
<ui:insert name="script"></ui:insert>
</script>
<title>
<ui:insert name="title">Login</ui:insert>
</title>
</h:head>
<h:body>
<div id="top">
<ui:insert name="top">
<ui:include src="header.xhtml" id="header"/>
</ui:insert>
</div>
<div>
<div id="content">
<ui:insert name="content"></ui:insert>
</div>
</div>
<div id="bottom" style="position: absolute;top: 675px;width: 100%" align="center">
<ui:insert name="bottom">
<ui:include src="footer.xhtml" id="footer"/>
</ui:insert>
</div>
</h:body>
</html>
在我的页面上,我正在使用类似的东西
on my page i am using something like this
<h:body>
<ui:composition template="./WEB-INF/templates/layout.xhtml">
<ui:define name="script"></ui:define>
<ui:define name="title">#{faqAddUpdate.actionState} FAQ</ui:define>
<ui:define name="content">
....
</ui:define>
</ui:composition>
此添加javascript标记在我的页面头部.现在,我想问一下是否要在页面上添加另一个.js文件.我将必须在我的layout.xhtml页面中这样定义另一个ui:insert name ="script"吗?
This add javascript tag in my page head section.Now i want to ask if i want to add another .js file on my page. The i will have to define another ui:insert name="script" in my layout.xhtml page like this?
<script type="textext/javascript" src="js/1.js" >
<ui:insert name="script"></ui:insert>
</script>
<script type="textext/javascript" src="js/2.js" >
<ui:insert name="script"></ui:insert>
</script>
,依此类推.还是有什么技巧可以在layout.xhtml中定义一次脚本标记,然后根据src属性,将其插入到ui:composition页面中?
and so on. Or is there any trick that i define script tag in my layout.xhtml once and then on the basis of src attribute, i insert it on my ui:composition page?
谢谢
推荐答案
您不必使用ui:inserts来执行此操作.无论您需要在页面中的何处添加javascript文件.只需使用资源API这样添加即可.
You do not have to do this using ui:inserts. Wherever you need to add a javascript file in your pages. Just add like this using resource API.
<h:outputScript library="javascript" name="1.js" target="head" />
为此文件夹创建WebContent/resources/javascript,然后将1.js放在javascript文件夹中.
For this create folder WebContent/resources/javascript and put that 1.js in javascript folder.
这篇关于使用ui:composition时如何在页面上添加不同的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!