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

时间:2016-03-15 12:28:26

标签: orbeon

[形式助洗剂]

好的,所以这已成为两个问题,因为试图让一些示例代码工作时出现问题。

我有一个对password-check控件有操作的表单,该控件挂钩到password-check事件上以运行一些自定义操作和提交事件,该事件被调度到该控件。表单构建器提交按钮已配置自定义操作,其中一个操作是将Password事件分派给Password控件。一切正常。

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

已发布的表单包含所需的提交和操作,但调度的事件未到达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

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

所以主要问题是如果Password控件位于库的包含部分中,如何将事件分派到<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> 控件?

子问题是为什么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

<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 /文库

<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>

TEST / form1中

{{1}}

1 个答案:

答案 0 :(得分:0)

您无法使用xf:dispatch()定位部分模板内的控件,因为部分模板中的控件与使用XBL的“外部世界”“隔离”。 (考虑到表单中可能有多个节模板实例,这意味着您无法使用在创建节模板时选择的控件名称来引用表单中的控件名称。)

我们可以想象某些版本的xf:dispatch()可以定位部分模板内的控件,但是它还需要将该部分模板的名称作为参数。事实上,这是一个可以使用的解决方法:

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