xf:dispatch 操作不适用于库组件控件

xf:dispatch action does not work on library component control

[表单​​生成器]

好的,由于试图让一些示例代码工作时出现问题,所以这变成了两个问题。

我有一个表单,该表单在 Password 控件上有一个操作,该控件连接到 password-check 事件以 运行 一些自定义操作和提交事件被分派到该控件.表单构建器提交按钮配置了自定义操作,其中之一是将 password-check 事件分派给 Password 控件。这一切都有效。

由于需要使用相同的 Password 控件创建多个表单,我想将包含 Password 控件及其相关操作和提交的部分移动到部分库.我已将该部分移至应用程序的部分库并使用部分模板重建表单。

已发布的表单按预期包含所需的提交和操作,但调度的事件未到达 Password 控件(在调试日志中,我可以看到自定义操作 运行ning 和正在调度的事件,但它没有找到(?)控件(见下文):

2016-03-15 12:07:10,439 DEBUG XFormsServer  -   process: combining with then {action: "ActionNode(xf:dispatch,Map(Some(name) -> password-check, Some(targetid) -> Password-control))"}
2016-03-15 12:07:10,439 DEBUG XFormsServer  -   start process: running action {action: "ActionNode(xf:dispatch,Map(Some(name) -> password-check, Some(targetid) -> Password-control))"}
2016-03-15 12:07:10,439 DEBUG XFormsServer  -   end process: running action {time (ms): "0", result: "success"}

(相对于下面):

2016-03-15 12:09:26,385 DEBUG XFormsServer  -   start process: running action {action: "ActionNode(xf:dispatch,Map(Some(name) -> password-check, Some(targetid) -> Password-control))"}
2016-03-15 12:09:26,386 DEBUG XFormsServer  -           start dispatching {name: "password-check", target: "SignOff-control≡xf-637≡Password-control"}
2016-03-15 12:09:26,386 DEBUG XFormsServer  -             start handler {name: "password-check", phase: "target", observer: "SignOff-control≡xf-637≡Password-control"}
2016-03-15 12:09:26,386 DEBUG XFormsServer  -               interpreter - start executing {action name: "xf:action"}
2016-03-15 12:09:26,386 DEBUG XFormsServer  -                 interpreter - start executing {action name: "xxf:script"}

为了在这个问题中包含一些源代码,我创建了一个仅包含 Password 控件(和一个测试按钮)的表单和库,但我注意到发布的表单中没有包含这些操作(form1).

所以主要问题是,如果 Password 控件位于库的包含部分中,我如何将事件分派给 Password 控件?

子问题是为什么 form1 的已发布版本中没有包含操作?我看到 "Actions involving controls in a given section are automatically included with the section template, along with the services called by the actions.",我认为下面的示例代码就是这种情况。

属性-local.xml

<property as="xs:string" name="oxf.fr.detail.buttons.TEST.*">
  cancel
  submit
</property>

<property as="xs:string" name="oxf.fr.detail.process.submit.TEST.*">
  xf:dispatch(name = "password-validate", targetid = "field-control")
  then require-valid
  then xf:send("StoreDocument-submission")
</property>

TEST/library

<xh:html xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:sql="http://orbeon.org/oxf/xml/sql"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
         xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:exf="http://www.exforms.org/exf/1-0">
    <xh:head>
        <xh:title>Test Library</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>
                    <Section>
                        <field/>
                        <button/>
                    </Section>
                </form>
            </xf:instance>

            <!-- Bindings -->
            <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
                <xf:bind id="Section-bind" name="Section" ref="Section">
                    <xf:bind id="field-bind" name="field" ref="field"/>
                    <xf:bind id="button-bind" ref="button" name="button"/>
                </xf:bind>
            </xf:bind>

            <!-- Metadata -->
            <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
                <metadata>
                    <application-name>TEST</application-name>
                    <form-name>library</form-name>
                    <title xml:lang="en">Test Library</title>
                    <description xml:lang="en"/>
                    <singleton>false</singleton>
                </metadata>
            </xf:instance>

            <!-- Attachments -->
            <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
                <attachments>
                    <css mediatype="text/css" filename="" size=""/>
                    <pdf mediatype="application/pdf" filename="" size=""/>
                </attachments>
            </xf:instance>

            <!-- All form resources -->
            <!-- Don't make readonly by default in case a service modifies the resources -->
            <xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
                <resources>
                    <resource xml:lang="en">
                        <Section>
                            <label>Section</label>
                        </Section>
                        <field>
                            <label/>
                            <hint/>
                        </field>
                        <button>
                            <label>Button</label>
                            <hint/>
                        </button>
                    </resource>
                </resources>
            </xf:instance>

            <!-- Utility instances for services -->
            <xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
                <request/>
            </xf:instance>
            <xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
                <response/>
            </xf:instance>
            <xf:action id="field-revalidate" ev:event="password-check" ev:observer="field-control">
                <xxf:script>
                    console.log('running revalidate');
                </xxf:script>
            </xf:action>
            <xf:action id="button-action" ev:event="DOMActivate" ev:observer="button-control">
                <xf:dispatch name="password-check" targetid="field-control"/>
            </xf:action>
        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
                     xmlns:oxf="http://www.orbeon.com/oxf/processors"
                     xmlns:p="http://www.orbeon.com/oxf/pipeline">
                <fr:section id="Section-control" bind="Section-bind">
                    <xf:label ref="$form-resources/Section/label"/>
                    <fr:grid>
                        <xh:tr>
                            <xh:td>
                                <xf:input id="field-control" bind="field-bind">
                                    <xf:label ref="$form-resources/field/label"/>
                                    <xf:hint ref="$form-resources/field/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                </xf:input>
                            </xh:td>
                            <xh:td>
                                <xf:trigger id="button-control" bind="button-bind">
                                    <xf:label ref="$form-resources/button/label"/>
                                    <xf:hint ref="$form-resources/button/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                </xf:trigger>
                            </xh:td>
                        </xh:tr>
                    </fr:grid>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

TEST/form1

<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" xmlns:xf="http://www.w3.org/2002/xforms"
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:ev="http://www.w3.org/2001/xml-events"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
         xmlns:xxf="http://orbeon.org/oxf/xml/xforms"
         xmlns:exf="http://www.exforms.org/exf/1-0"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:sql="http://orbeon.org/oxf/xml/sql"
         xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
         xmlns:fb="http://orbeon.org/oxf/xml/form-builder">
    <xh:head>
        <xh:title>Form 1</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>
                    <Section>
                        <field/>
                        <button/>
                    </Section>
                </form>
            </xf:instance>

            <!-- Bindings -->
            <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
                <xf:bind id="Section-bind" ref="Section" name="Section"/>
            </xf:bind>

            <!-- Metadata -->
            <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
                <metadata>
                    <application-name>TEST</application-name>
                    <form-name>form1</form-name>
                    <title xml:lang="en">Untitled Form</title>
                    <description xml:lang="en"/>
                    <singleton>false</singleton>
                </metadata>
            </xf:instance>

            <!-- Attachments -->
            <xf:instance id="fr-form-attachments" xxf:exclude-result-prefixes="#all">
                <attachments>
                    <css mediatype="text/css" filename="" size=""/>
                    <pdf mediatype="application/pdf" filename="" size=""/>
                </attachments>
            </xf:instance>

            <!-- All form resources -->
            <!-- Don't make readonly by default in case a service modifies the resources -->
            <xf:instance id="fr-form-resources" xxf:readonly="false" xxf:exclude-result-prefixes="#all">
                <resources>
                    <resource xml:lang="en">
                        <Section>
                            <label>Section</label>
                            <help/>
                        </Section>

                    </resource>
                </resources>
            </xf:instance>

            <!-- Utility instances for services -->
            <xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
                <request/>
            </xf:instance>

            <xf:instance id="fr-service-response-instance" xxf:exclude-result-prefixes="#all">
                <response/>
            </xf:instance>

        </xf:model>
    </xh:head>
    <xh:body>
        <fr:view>
            <fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
                     xmlns:oxf="http://www.orbeon.com/oxf/processors"
                     xmlns:p="http://www.orbeon.com/oxf/pipeline">
                <fr:section id="Section-control" bind="Section-bind">
                    <xf:label ref="$form-resources/Section/label"/>
                    <component:Section xmlns:component="http://orbeon.org/oxf/xml/form-builder/component/TEST/library"
                                       xmlns="http://orbeon.org/oxf/xml/form-builder"
                                       xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
                                       xmlns:fbf="java:org.orbeon.oxf.fb.FormBuilder"/>
                </fr:section>
            </fr:body>
        </fr:view>
    </xh:body>
</xh:html>

您不能使用 xf:dispatch() 将部分模板内的控件作为目标,因为部分模板内的控件是 "insulated" 来自使用 XBL 的 "outside world"。 (考虑到您可以在一个表单中拥有多个部分模板实例,这意味着您不能使用在创建部分模板时选择的控件名称来引用表单中的那些控件。)

我们可以想象 xf:dispatch() 的某些版本可以将控件定位到部分模板内,但它还需要将该部分模板的名称作为参数。就目前情况而言,您可以使用以下解决方法:

  1. 在您的部分模板中,添加一个输出控件,并使用 CSS 将其隐藏。将其初始值设置为 1。
  2. 不使用 xf:dispatch(),而是使用 xf:setvalue() 并将字段值递增 1。
  3. 当您在输出字段上获得 xforms-value-changed 时,调度 password-check 事件。这将起作用,因为它是在部分模板中完成的。