Custom control: dropdown values from XML file

落爺英雄遲暮 提交于 2019-12-04 18:00:56

Creating XBL components is tricky. At least the first time you do it. A few things:

  1. To avoid confusions, I recommend you define components in your own namespace. In the example below, I used xmlns:my="http://www.example.com/".
  2. The content of fb:template is how using the component looks like, not its implementation. So, it should look like:

    <fb:template>
        <my:country-selector>
            <xforms:label ref=""/>
            <xforms:hint ref=""/>
            <xforms:help ref=""/>
            <xforms:alert ref=""/>
        </my:country-selector>
    </fb:template>
    
  3. The implementation is inside xbl:template.

  4. So the component can be found at runtime, you need to place it in a directory xbl/my/country-selector/country-selector.xbl. The my part of the directory is mapped to the namespace by you adding the following property in your properties-local.xml:

    <property as="xs:string"  name="oxf.xforms.xbl.mapping.my"
                              value="http://www.example.com/"/>
    

    (Often, we use the same name for the directory and the prefix, but they don't need to be the same. E.g. the fr:* components are in a directory called orbeon.)

  5. So Form Builder shows your component in the sidebar, you need to add a property like:

    <property as="xs:string"  name="oxf.fb.toolbox.group.other.uri.*.*"
              value="oxf:/xbl/my/country-selector/country-selector.xbl"/>
    

And here is the full source for country-selector.xbl:

<xbl:xbl xmlns:xh="http://www.w3.org/1999/xhtml"
         xmlns:xforms="http://www.w3.org/2002/xforms"
         xmlns:xs="http://www.w3.org/2001/XMLSchema"
         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:my="http://www.example.com/"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:fb="http://orbeon.org/oxf/xml/form-builder"
         xmlns:xbl="http://www.w3.org/ns/xbl"
         xmlns:xxbl="http://orbeon.org/oxf/xml/xbl">

    <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
        <display-name lang="en">Custom Controls</display-name>
    </metadata>

    <xbl:binding id="my-country-selector" element="my|country-selector" xxbl:mode="lhha binding value">
        <fb:metadata>
            <fb:display-name lang="en">Country Selector</fb:display-name>
            <fb:icon lang="en">
                <fb:small-icon>/forms/orbeon/builder/images/dropdown.png</fb:small-icon>
                <fb:large-icon>/forms/orbeon/builder/images/dropdown.png</fb:large-icon>
            </fb:icon>
            <fb:datatype>xforms:string</fb:datatype>
            <fb:template>
                <my:country-selector>
                    <xforms:label ref=""/>
                    <xforms:hint ref=""/>
                    <xforms:help ref=""/>
                    <xforms:alert ref=""/>
                </my:country-selector>
            </fb:template>
        </fb:metadata>
        <xbl:template>
            <xforms:select1 appearance="minimal" ref="xxf:binding('my-country-selector')">
                <xforms:item>
                    <xforms:label>[Select...]</xforms:label>
                    <xforms:value/>
                </xforms:item>
                <xforms:itemset nodeset="doc('oxf:/forms/orbeon/controls/service/countries.xml')/countries/country">
                    <xforms:label ref="name"/>
                    <xforms:value ref="us-code"/>
                </xforms:itemset>
            </xforms:select1>
        </xbl:template>
    </xbl:binding>
</xbl:xbl>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!