2016-03-15 40 views
0

[形式建设者]XF:调度操作不会对库组件控制

确定因工作问题,所以这也成为了两个问题想获得一些示例代码工作。

我有一个表单,它有一个挂钩在password-check事件上的Password控件上的动作,以运行一些自定义动作和提交事件,该事件被分派到该控件。表单构建器提交按钮已配置了自定义操作,其中之一是将password-check事件分派给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控制(和测试b utton),但注意到这些操作未包含在已发布的表单(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 /库

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

我并不感到惊讶的是,'密码check'事件没有达到你的控制时的控制是一款模板中,作为部分模板功能创建和XBL组件适合你,它屏蔽来自控件“外部世界”,反之亦然。 “谁”将该事件分派到密码字段? – avernet

+0

当用户通过使用提交按钮' xf:dispatch(name =”password-validate“,targetid =”field-control“)...' – bytesnz

+0

明白了,谢谢您的详细信息,我已在下面发布了答案。 – avernet

回答

0

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

我们可以想象一下xf:dispatch()的某个版本,它可以将节目模板中的控件作为目标,但它也需要将该节模板的名称作为参数。按照事实,这里是一个可以使用的解决方法:

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

谢谢@avernet – bytesnz

+0

不客气,我很高兴这有助于。 – avernet