【问题标题】:xf:dispatch action does not work on library component controlxf:dispatch 操作不适用于库组件控件
【发布时间】:2016-03-15 12:28:25
【问题描述】:

[表单生成器]

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

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

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

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

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.",我认为下面的示例代码就是这种情况。

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

测试/库

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

测试/表格1

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

【问题讨论】:

  • password-check 事件未到达您的控件时,当该控件位于节模板内时,我并不感到惊讶,因为节模板功能会为您创建 XBL 组件,从而保护控件免受“外部世界”,反之亦然。 “谁”将该事件发送到密码字段?
  • 当用户通过使用提交按钮&lt;property as="xs:string" name="oxf.fr.detail.process.submit.TEST.*"&gt; xf:dispatch(name = "password-validate", targetid = "field-control") ...987654338@上的自定义操作点击表单构建器提交按钮时,事件正在被调度
  • 知道了,谢谢你的详细信息,我已经在下面发布了答案。

标签: orbeon


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 2021-01-27
    • 2017-02-17
    相关资源
    最近更新 更多