我正在使用Orbeon v2017.1,并试图在部分模板中创建服务,该服务应检索默认国家/地区的标签,该标签应在自动完成字段中预先选择(国家)。
仅当用户未输入值(或加载表格时)时,我才想预选国家/地区。它应该支持多种语言。
如果我在“表单加载”之后和“控件准备就绪”之后触发操作,它将调用我的服务,但仅针对 library 表单。对于包括此可重用部分的所有其他形式,不会调用该服务。
还有其他方法可以实现吗?预先感谢。
编辑
下面是设置控件值的自动完成字段,服务和操作的示例
<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:title/>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance id="all-countries"
src="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/ListOfCountryNamesByName/XML"/>
<!-- Main instance -->
<xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<country-dynamic-autocomplete label=""/>
</section-1>
</form>
</xf:instance>
<!-- Bindings -->
<xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="country-dynamic-autocomplete-bind" ref="country-dynamic-autocomplete"
name="country-dynamic-autocomplete"/>
</xf:bind>
</xf:bind>
<!-- Metadata -->
<xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>insurance</application-name>
<form-name>test</form-name>
<title xml:lang="en"/>
<description xml:lang="en"/>
</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">
<country-dynamic-autocomplete>
<label>Countries Preselect Value</label>
<hint/>
</country-dynamic-autocomplete>
<section-1>
<label>Country Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
<xf:instance id="get-default-country-value-instance" class="fr-service"
xxf:exclude-result-prefixes="#all">
<body xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fbf="java:org.orbeon.oxf.fb.FormBuilder"><params/></body>
</xf:instance>
<xf:submission id="get-default-country-value-submission" class="fr-service"
resource="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/CountryName/XML/debug?sCountryISOCode=DE"
method="get"
serialization="none"
mediatype="none"/>
<xf:action id="set-country-default-value-binding">
<xf:action event="DOMActivate" ev:observer="country-dynamic-autocomplete-control"
if="true()">
<xf:send submission="get-default-country-value-submission"/>
</xf:action>
<xf:action event="xforms-submit" ev:observer="get-default-country-value-submission">
<xf:var name="request-instance-name" value="'get-default-country-value-instance'"/>
<xf:action/>
</xf:action>
<xf:action event="xforms-submit-done" ev:observer="get-default-country-value-submission">
<xf:action class="fr-set-control-value-action">
<xf:var name="control-name" value="'country-dynamic-autocomplete'"/>
<xf:var name="control-value" value="/string"/>
</xf:action>
</xf:action>
</xf:action>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<fr:autocomplete xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
id="country-dynamic-autocomplete-control"
labelref="@label"
max-results-displayed="300"
resource="http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso/ListOfCountryNamesByName/XML"
bind="country-dynamic-autocomplete-bind">
<xf:label ref="$form-resources/country-dynamic-autocomplete/label"/>
<xf:hint ref="$form-resources/country-dynamic-autocomplete/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="/ArrayOftCountryCodeAndName/tCountryCodeAndName">
<xf:label ref="sName"/>
<xf:value ref="sISOCode"/>
</xf:itemset>
</fr:autocomplete>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
编辑2(新服务):
<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:title/>
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<xf:instance id="all-countries" src="http://api.worldbank.org/v2/countries/"/>
<!-- Main instance --> <xf:instance id="fr-form-instance" xxf:exclude-result-prefixes="#all" xxf:index="id">
<form>
<section-1>
<country-dynamic-autocomplete label=""/>
<control-3/>
</section-1>
</form>
</xf:instance>
<!-- Bindings --> <xf:bind id="fr-form-binds" ref="instance('fr-form-instance')">
<xf:bind id="section-1-bind" name="section-1" ref="section-1">
<xf:bind id="country-dynamic-autocomplete-bind" ref="country-dynamic-autocomplete"
name="country-dynamic-autocomplete"/>
<xf:bind id="control-3-bind" ref="control-3" name="control-3" xxf:whitespace="trim"/>
</xf:bind>
</xf:bind>
<!-- Metadata --> <xf:instance xxf:readonly="true" id="fr-form-metadata" xxf:exclude-result-prefixes="#all">
<metadata>
<application-name>insurance</application-name>
<form-name>test</form-name>
<title xml:lang="en"/>
<description xml:lang="en"/>
</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">
<country-dynamic-autocomplete>
<label>Countries Preselect Value</label>
<hint/>
</country-dynamic-autocomplete>
<control-3>
<label>XML</label>
<hint/>
</control-3>
<section-1>
<label>Country Section</label>
</section-1>
</resource>
</resources>
</xf:instance>
<xf:instance id="get-default-country-value-instance" class="fr-service"
xxf:exclude-result-prefixes="#all">
<body xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fbf="java:org.orbeon.oxf.fb.FormBuilder"><params/></body>
</xf:instance>
<xf:submission id="get-default-country-value-submission" class="fr-service"
resource="http://restcountries.eu/rest/v2/name/deutschland"
method="get"
serialization="none"
mediatype="none"/>
<xf:instance id="json-to-xml-instance" class="fr-service" xxf:exclude-result-prefixes="#all">
<body xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:fbf="java:org.orbeon.oxf.fb.FormBuilder"><params/></body>
</xf:instance>
<xf:submission id="json-to-xml-submission" class="fr-service"
resource="http://restcountries.eu/rest/v2/all"
method="get"
serialization="none"
mediatype="none"/>
<xf:action id="show-json-in-xml-binding">
<xf:action event="fr-run-form-load-action-after-controls" ev:observer="fr-form-model"
if="true()">
<xf:send submission="json-to-xml-submission"/>
</xf:action>
<xf:action event="xforms-submit" ev:observer="json-to-xml-submission">
<xf:var name="request-instance-name" value="'json-to-xml-instance'"/>
<xf:action/>
</xf:action>
<xf:action event="xforms-submit-done" ev:observer="json-to-xml-submission">
<xf:action class="fr-set-control-value-action">
<xf:var name="control-name" value="'control-3'"/>
<xf:var name="control-value" value="saxon:serialize(., 'xml')"/>
</xf:action>
</xf:action>
</xf:action>
<xf:action id="set-country-default-value-binding">
<xf:action event="DOMActivate" ev:observer="country-dynamic-autocomplete-control"
if="true()">
<xf:send submission="get-default-country-value-submission"/>
</xf:action>
<xf:action event="xforms-submit" ev:observer="get-default-country-value-submission">
<xf:var name="request-instance-name" value="'get-default-country-value-instance'"/>
<xf:action/>
</xf:action>
<xf:action event="xforms-submit-done" ev:observer="get-default-country-value-submission">
<xf:action class="fr-set-control-value-action">
<xf:var name="control-name" value="'country-dynamic-autocomplete'"/>
<xf:var name="control-value" value="saxon:serialize(., 'xml')"/>
</xf:action>
</xf:action>
</xf:action>
</xf:model>
</xh:head>
<xh:body>
<fr:view>
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl" xmlns:p="http://www.orbeon.com/oxf/pipeline"
xmlns:oxf="http://www.orbeon.com/oxf/processors">
<fr:section id="section-1-control" bind="section-1-bind">
<xf:label ref="$form-resources/section-1/label"/>
<fr:grid>
<xh:tr>
<xh:td>
<fr:autocomplete xmlns:xxbl="http://orbeon.org/oxf/xml/xbl"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
id="country-dynamic-autocomplete-control"
labelref="@label"
max-results-displayed="300"
resource="http://restcountries.eu/rest/v2/all"
bind="country-dynamic-autocomplete-bind">
<xf:label ref="$form-resources/country-dynamic-autocomplete/label"/>
<xf:hint ref="$form-resources/country-dynamic-autocomplete/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
<xf:itemset ref="/_/name">
<xf:label ref="name"/>
<xf:value ref="alpha2Code"/>
</xf:itemset>
</fr:autocomplete>
</xh:td>
</xh:tr>
<xh:tr>
<xh:td>
<xf:input id="control-3-control" bind="control-3-bind">
<xf:label ref="$form-resources/control-3/label"/>
<xf:hint ref="$form-resources/control-3/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
</xh:td>
</xh:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xh:body>
</xh:html>