我是Orbeon xforms的新手,所以我在这里问我的问题。我有REST webservice和一些地址(方法GET),我想打电话给他,结果应该提供给我的表格的元数据:
<!-- Main instance -->
<xforms:instance id="fr-form-instance">
<form>
<section-meta>
<resultOfMyRestWebservice/>
我已经尝试按照本教程http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data(拉解决方案)但我不知道如何将休息结果放在标记中:resultOfMyRestWebservice,以及我必须提交提交代码的地方:
<xforms:submission
id="load-data-submission"
method="get" serialization="none"
resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
replace="?" instance="?"/>
问候
答案 0 :(得分:1)
如果我是你,我会使用临时运行时实例来保存REST调用的结果,然后使用setvalue来填充持久化实例。
如果您在模型中定义元数据的结构,则以下示例有效,因此您可以使用setvalue进行填充。否则你可以使用insert。
IE中。在你的xforms:model define:
<!-- Run-time instance to hold Service response -->
<xforms:instance id="fr-service-response-instance" xxforms:exclude-result-prefixes="#all">
<response/>
</xforms:instance>
定义您的提交以替换此响应实例:
<xforms:submission id="load-data-submission" method="get"
serialization="none" mediatype="application/xml"
resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
replace="instance" instance="fr-service-response-instance"/>
然后创建一个动作来调用提交并填充您的实例:
<!-- Populate Data
uses Load Data Submission
runs on form load -->
<xforms:action id="populate-data-binding">
<xforms:action ev:event="xforms-ready" ev:observer="fr-form-model" if="true()">
<xforms:send submission="load-data-submission"/>
</xforms:action>
<!-- Populate resultOfMyRestWebservice control with pathToResults value
following successful submission -->
<xforms:action ev:event="xforms-submit-done" ev:observer="load-data-submission"
context="instance('fr-service-response-instance')">
<xforms:action>
<xf:var name="control-name" value="'resultOfMyRestWebservice'" as="xs:string"/>
<xf:var name="control-value" value="/pathToResults" as="xs:string"/>
<xforms:setvalue ref="instance('fr-form-instance')/*/*[name() = $control-name]"
value="$control-value"/>
</xforms:action>
</xforms:action>
</xforms:action>
注意pathToResults是您希望从结果中获取的值的xpath。
答案 1 :(得分:0)
我在提到的教程中做了所有事情:http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data我的意思是:
....
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<!-- User in which user data is collected -->
<xf:instance id="user-data">
<registration>
<first-name/>
<last-name/>
</registration>
</xf:instance>
<!-- Load initial data from a service -->
<xf:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
<xf:submission id="load-data-submission" method="get" serialization="none"
resource="http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml"
replace="instance"
instance="user-data"/>
<!-- Main instance -->
<xf:instance id="fr-form-instance">
<form>
<name/>
....
....
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel"
xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline">
....
<xforms:action ev:event="xforms-enabled">
<xforms:setvalue ref="xxf:instance('fr-form-instance')/name"
value="xxf:instance('user-data')/first-name"/>
</xforms:action>
</fr:body>
....
我想从链接(http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml)获取xml,输入'user-data'实例,然后获取名字并将其放入'fr-form-中的'name'标记实例”。不幸的是它不起作用,我的意思是setvalue无法正常工作,因为当我像这样更改'user-instance'时:
<xf:instance id="user-data">
<registration>
<first-name>SomeName</first-name>
<last-name/>
</registration>
</xf:instance>
它工作,最终的xml看起来像:
....
<name>SomeName</name>
....
我真的不知道为什么它不起作用。
问候
///
现在我看到我的问题可能会减少到:
有效:
<xforms:instance id="user-data" src="http://example.org/service/load-initial-form-data-pull-instance"/>
它不起作用:
<xforms:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
<xforms:submission id="load-data-submission"
method="get" serialization="none"
resource="http://example.org/service/load-initial-form-data-pull-instance"
replace="instance" instance="user-data"/>
我必须使用第二种方式,因为我必须将一些参数传递给资源(resource =“http ... / {xxforms:get-request-parameter('myParam')}”)