通过 Oracle ADF 中的 af:declarativeComponent 向部分加载的 <head> 部分添加 <script> 标记

Add a <script> tag to the <head> section from a partial loaded via af:declarativeComponent in Oracle ADF

我有一个只有几页的 ADF 项目 (JDeveloper 11)。所有页面加载包含顶部导航栏的部分文件,如下所示:

mainFile.jspx

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">

  <jsp:directive.page contentType="text/html;charset=UTF-8"/>
  <f:view>
    <af:document id="d1"">

      <af:declarativeComponent id="dc0" viewId="/partials/header-small.jspx" />
....

在部分文件中我有这个:

header-small.jspx

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:af="http://xmlns.oracle.com/adf/faces/rich">

  <jsp:directive.page contentType="text/html;charset=UTF-8"/>

    <link rel="stylesheet" href="some-stylesheet-file.css"/>

    <script src="javascripts/modernizr.js"></script>
    <script src="javascripts/fonts.js"></script>

    <header class="top_header" role="presentation">
....

就像现在一样,linkscript 标签被添加到 <body> 部分,但我想要它们在 <head> 中。我找不到任何合适的方法来做到这一点。有可能吗?

我现在无法实现模板,因为该项目是由其他人创建的,不可用,我只负责front-end。

要获取 <head> 标签内的脚本和 link,恐怕您需要将样式 sheet 和 javascript 资源放在 mainFile.jspx:

 <af:document>
   <af:resource type="javascript" source="../javascripts/modernizr.js">
   <af:resource type="javascript" source="../some-stylesheet-file.css">
  <af:form> 
   ...
  </af:form> 
</af:document>

因此,您可能无法获得高度封装。 更多细节,在这里: https://blogs.oracle.com/jdevotnharvest/entry/gotcha_when_using_javascript_in