Orbeon JavaScript API - 从 fr:section 内部获取控制值?

Orbeon JavaScript API - Access to control value from within fr:section?

fr:section 中嵌入的 xf:triggers 似乎有问题,请参阅以下两个示例表格。

有任何已知的解决方法吗?

触发器未嵌入 fr:section - 工作正常

<xh:html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:exf="http://www.exforms.org/exf/1-0" xmlns:fb="http://orbeon.org/oxf/xml/form-builder" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:saxon="http://saxon.sf.net/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sql="http://orbeon.org/oxf/xml/sql" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
    <xh:head>
        <xh:title>Test Form</xh:title>
        <xf:model id="fr-form-model" xxf:expose-xpath-types="true">
            <!-- Main instance -->
            <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
                <form>
                    <message-section>
                        <message>my message</message>
                    </message-section>
                </form>
            </xf:instance>
            <!-- Metadata -->
            <xf:instance id="fr-form-metadata" xxf:exclude-result-prefixes="#all" xxf:readonly="true">
                <metadata>
                    <application-name>test-app</application-name>
                    <form-name>client-js-sample</form-name>
                    <title xml:lang="en">Test Form</title>
                    <description xml:lang="en"/>
                    <singleton>false</singleton>
                </metadata>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xbl="http://www.w3.org/ns/xbl">
                <xf:output id="message" ref="message-section/message"/>
                <xf:trigger>
                    <xf:label>Show</xf:label>
                    <xxf:script ev:event="DOMActivate" type="javascript">
                        var message = ORBEON.xforms.Document.getValue("message");
                        window.alert("message:" + message);
                    </xxf:script>
                </xf:trigger>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

触发器嵌入 fr:section - 不起作用

一旦 xf:trigger 嵌入 fr:section,Orbeon JavaScript API 就不再找到控件 message。这是相同的基本形式,除了额外的 fr:section.

<xh:html xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:exf="http://www.exforms.org/exf/1-0" xmlns:fb="http://orbeon.org/oxf/xml/form-builder" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:saxon="http://saxon.sf.net/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sql="http://orbeon.org/oxf/xml/sql" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xxf="http://orbeon.org/oxf/xml/xforms" xmlns:xxi="http://orbeon.org/oxf/xml/xinclude">
    <xh:head>
        <xh:title>Test Form</xh:title>
        <xf:model id="fr-form-model" xxf:expose-xpath-types="true">
            <!-- Main instance -->
            <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all">
                <form>
                    <message-section>
                        <message>my message</message>
                    </message-section>
                </form>
            </xf:instance>
            <!-- Metadata -->
            <xf:instance id="fr-form-metadata" xxf:exclude-result-prefixes="#all" xxf:readonly="true">
                <metadata>
                    <application-name>test-app</application-name>
                    <form-name>client-js-sample</form-name>
                    <title xml:lang="en">Test Form</title>
                    <description xml:lang="en"/>
                    <singleton>false</singleton>
                </metadata>
            </xf:instance>
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:xbl="http://www.w3.org/ns/xbl">
                <fr:section>
                    <xf:label>Test Section</xf:label>
                    <xf:output id="message" ref="message-section/message"/>
                    <xf:trigger>
                        <xf:label>Show</xf:label>
                        <xxf:script ev:event="DOMActivate" type="javascript">
                       var message = ORBEON.xforms.Document.getValue("message");
                        window.alert("message:" + message);
                    </xxf:script>
                    </xf:trigger>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

发生这种情况是因为该部分是 XBL 控件,当您的控件位于 XBL 控件内时,在生成的 HTML 中,容器的 ID 作为前缀添加到您的 ID控制。所以你可以使用:

var messageControl = ORBEON.jQuery('*[id $= "message"]')[0];
alert(ORBEON.xforms.Document.getValue(messageControl));

有关这方面的更多信息,请参阅有关 how to use getValue() and setValue() on forms created with Form Builder 的文档部分。