我在Orbeon Form runner中有一个表单,我需要在使用'workflow-send'提交之前添加外部验证。我们可以在properties-local.xml中添加“workflow-send”按钮的功能吗?
为了记录,我还实现了一个按钮,该按钮执行验证并在验证结果返回时执行某些操作。那么,我们可以将“工作流程发送”功能添加到我的那个按钮吗?
答案 0 :(得分:1)
我通过对persistence-model.xml文件进行一些更改来完成此操作。这种验证需要在持久性阶段完成。因为,我们需要的是在保存数据之前调用的服务器端验证(访问数据库等),显然是在工作流发送之前。
我已经注释掉旧的代码片段。
<!-- Respond to send button activation -->
<xforms:action ev:event="DOMActivate" ev:observer="fr-workflow-send-button">
<xforms:send submission="validation-submission" />
<!-- xforms:setvalue ref="instance('fr-persistence-instance')/submit-or-save-or-send">send</xforms:setvalue>
<xforms:dispatch name="fr-save-action" target="fr-persistence-model"> <xxforms:context
name="fr:check-data-valid" select="true()" /> </xforms:dispatch -->
</xforms:action>
<xforms:action ev:event="my-valid-action">
<xforms:setvalue
ref="instance('fr-persistence-instance')/submit-or-save-or-send">send</xforms:setvalue>
<xforms:dispatch name="fr-save-action" target="fr-persistence-model">
<xxforms:context name="fr:check-data-valid" select="true()" />
</xforms:dispatch>
</xforms:action>
<xforms:instance id="validation-result">
<dummy />
</xforms:instance>
<xforms:submission id="validation-submission"
ref="xxforms:instance('fr-form-instance')" resource="http://localhost:8080/MyApp/OrbeonValidationServlet"
method="post" replace="instance" instance="validation-result">
<!-- Clear external errors just before doing external validation -->
<xforms:delete ev:event="xforms-submit" nodeset="//@v:*" />
<xforms:action ev:event="xforms-submit-done">
<!-- Insert external validation results when done -->
<xforms:insert nodeset="."
origin="instance('validation-result')/v:data/*" />
<!-- Show all errors on form -->
<xforms:dispatch name="fr-visit-all" targetid="error-summary" />
<!-- Update error summary for incremental mode -->
<xforms:refresh />
<xforms:dispatch name="fr-update" targetid="error-summary" />
<xforms:dispatch name="my-valid-action" target="fr-persistence-model"
if="count(instance('validation-result')/v:global-errors/*)
= 0" />
</xforms:action>
</xforms:submission>
所以基本上
最后一件事是将验证结果绑定到我的表单中的fr:error-summary。
可以尝试更加努力,并且可以从properties-local.xml中设置/ OrbeonValidationServlet。