使用模板时出现<h:outputScript>目标问题

asy*_*ard 5 jsf facelets

我有一个关于将jquery库与JSF 2.0集成的问题

使用时<h:outputScript library="/common/js" name="jquery-1.5.1.min.js" target="head" />,我应该<h:head>在我的xhtml文件中包含标签.所以脚本呈现在头部.

但我有一个包含<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>
Run Code Online (Sandbox Code Playgroud)

所以我有"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>
Run Code Online (Sandbox Code Playgroud)

asy*_*ard 6

我认为更好的方法可以解决我的问题:添加<ui:insert name="icerikhead"></ui:insert>到模板的头部,然后将其填入我的表单中<ui:define name="icerikhead"> add js files </ui:define>

  • 4年后,我遇到了同样的问题.在facelets`ui:composition`中使用`h:outputScript`时,不会呈现脚本标记.该facelet还使用模板并通过一些`ui:define`标签定义内容.然后我意识到,我必须将h:outputScript放在其中一个ui:define标签内,而不是在它们之外.现在它就像一个魅力. (4认同)