Orbeon 2018.1 无法从 html/head/script 访问 ORBEON 对象

Orbeon 2018.1 cannot access ORBEON object from html/head/script

从 Orbeon 2018.1 开始,ORBEON javascript 对象的加载方式发生了变化。以下内容用于 2017.2.2 和 3.9 版本。

Objective:我想使用适当的语言加载 TinyMCE 小部件。为此,我曾经有这样的代码:

<xh:script type="text/javascript">
    var lang = ORBEON.xforms.Document.getValue('language') ? ORBEON.xforms.Document.getValue('language').split('-')[0] : 'en';
    var TINYMCE_CUSTOM_CONFIG = {
        language:                  lang,
        ...

此 html/head 代码在版本 2018.1 中失败,因为 ORBEON 对象是 "undefined"。

我尝试将变量 lang 移动到我的模型中,如下所示:

<xf:instance id="language">
    <language/>
</xf:instance>
<xf:action ev:observer="language" ev:event="xxforms-value-changed">
    <xxf:script>
        var lang = ORBEON.xforms.Document.getValue('language') ? ORBEON.xforms.Document.getValue('language').split('-')[0] : 'en';

        TINYMCE_CUSTOM_CONFIG.language = lang;
    </xxf:script>
</xf:action>

但是现在代码失败了,因为它说 "java.lang.IllegalArgumentException: Cannot find control for id language"

我在这里错过了什么?

一般来说,在到达内联脚本时假设所有内容都已加载是很危险的。最好将 JavaScript 初始化推迟到以后。

默认情况下,Orbeon Forms 2018.1 no longer includes inline scripts and therefore JavaScript initialization is deferred. This was mainly done to help with the CSP header. You can re-enable inline scripts with the property (see doc),但最好将自己的初始化推迟到以后。