此问题与Stackoverflow中的上一个问题有关,建议使用事件在元素之间创建相关的依赖关系。
我有一个部分有一个问题的代码示例:
<xh:html xmlns:xh="http://www.w3.org/1999/xhtml" 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: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:meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<xh:title>StackOverflow</xh:title>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance id="fr-form-metadata" xxf:exclude-result-prefixes="#all" xxf:readonly="true">
<metadata>
<application-name>WebForms</application-name>
<form-name>StackOverflow_v1</form-name>
<title xml:lang="en">StackOverflow</title>
<description xml:lang="en">Version: 1. Modification date: 2015-06-10 10:18:18. Publication date: 2015-06-10 10:18:18.</description>
</metadata>
</xf:instance>
<xf:instance id="fr-form-instance">
<form>
<Category>
<Question/>
</Category>
</form>
</xf:instance>
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="Category-bind" name="Category" ref="/form/Category">
<xf:bind id="Question-bind" name="Question" ref="Question" required="true()"/>
</xf:bind>
</xf:bind>
<xf:instance id="fr-form-attachments">
<attachments>
<css filename="" mediatype="text/css" size=""/>
<pdf filename="" mediatype="application/pdf" size=""/>
</attachments>
</xf:instance>
<xf:instance id="fr-form-resources" xxf:readonly="false">
<resources>
<resource xml:lang="en">
<Category>
<label><![CDATA[Category]]></label>
<hint/>
<alert/>
<Question>
<label><![CDATA[Question]]></label>
<hint/>
<alert/>
<item>
<label><![CDATA[Answer]]></label>
<hint/>
<value><![CDATA[Answer]]></value>
</item>
<item>
<label><![CDATA[Answer2]]></label>
<hint/>
<value><![CDATA[Answer2]]></value>
</item>
</Question>
</Category>
</resource>
</resources>
</xf:instance>
<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>
<!-- Keep track of visible/hidden status -->
<xf:instance id="visible">
<var>
<Category>0</Category>
<Question>false</Question>
</var>
</xf:instance>
<!-- Change the visibility status for 'Question2'. -->
<xf:setvalue event="xforms-enabled" observer="Question-control" ref="instance('visible')/Question" value="'true'"/>
<xf:setvalue event="xforms-disabled" observer="Question-control" ref="instance('visible')/Question" value="'false'"/>
<!-- Update category showed elements count for 'Question2'. -->
<xf:setvalue event="xforms-enabled" observer="Question-control" ref="instance('visible')/Category" value="instance('visible')/Category + 1"/>
<xf:setvalue event="xforms-disabled" observer="Question-control" ref="instance('visible')/Category" value="instance('visible')/Category - 1"/>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" 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 bind="Category-bind" class="webforms-element webforms-category" id="Category-control">
<xf:label mediatype="text/html" ref="instance('fr-form-resources')/resource/Category/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/alert"/>
<xh:tr>
<xh:td>
<xf:select1 appearance="full" bind="Question-bind" class="webforms-element webforms-question" id="Question-control">
<xf:label mediatype="text/html" ref="instance('fr-form-resources')/resource/Category/Question/label"/>
<xf:hint ref="instance('fr-form-resources')/resource/Category/Question/hint"/>
<xf:alert ref="instance('fr-form-resources')/resource/Category/Question/alert"/>
<xf:itemset class="webforms-element webforms-answer" ref="instance('fr-form-resources')/resource/Category/Question/item">
<xf:label ref="label"/>
<xf:value ref="value"/>
<xf:hint ref="hint"/>
</xf:itemset>
</xf:select1>
</xh:td>
</xh:tr>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>
如上一篇文章所述,有两个事件可以保存问题的状态(如果可见或不可见),我添加了一个额外的事件来计算该类别中可见的元素数量。重要的代码在这里:
<xf:instance id="visible">
<var>
<Category>0</Category>
<Question>false</Question>
</var>
</xf:instance>
如果我将整个示例粘贴到Orbeon构建器版本4.9中,并使用源编辑器再次打开它,则代码已更改为:
<xf:instance id="visible">
<var>
<Category>1</Category>
<Question>true</Question>
</var>
</xf:instance>
似乎Orbeon Builder只运行事件并修改变量值,只需粘贴代码并在设计器中显示结果即可。因此,当保存到数据库并且我发布表单时,这个变量的最终值是最后一个。特别是每次编辑源代码时类别的计数器增加一个!
我认为这不是表单生成器中的期望行为(但它在Form Runner中),因此,问题是: 我可以在表单生成器中禁用事件的执行吗?