2

这是我的自定义控件:

<?xml version="1.0" encoding="UTF-8"?>

<xbl:xbl xmlns:xhtml="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:xxforms="http://orbeon.org/oxf/xml/xforms"
         xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
         xmlns:saxon="http://saxon.sf.net/"
         xmlns:xbl="http://www.w3.org/ns/xbl">

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

    <xbl:binding id="fb-input-country-selector" element="xforms|country-selector">
        <metadata xmlns="http://orbeon.org/oxf/xml/form-builder">
            <display-name lang="en">Country Selector</display-name>
            <icon lang="en">
                <small-icon>/forms/orbeon/builder/images/dropdown.png</small-icon>
                <large-icon>/forms/orbeon/builder/images/dropdown.png</large-icon>
            </icon>
            <datatype>xforms:string</datatype>
            <template>
                <xforms:select1 id="" appearance="minimal" ref="" xmlns="">
                    <xforms:label ref=""/>
                    <xforms:hint ref=""/>
                    <xforms:help ref=""/>
                    <xforms:alert ref="$fr-resources/detail/labels/alert"/>
                    <xforms:item>
                        <xforms:label>[Select...]</xforms:label>
                        <xforms:value/>
                    </xforms:item>
                    <xforms:itemset nodeset="doc('oxf:/apps/xforms-controls/services/countries.xml')/countries/country">
                        <xforms:label ref="name"/>
                        <xforms:value ref="us-code"/>
                    </xforms:itemset>
                </xforms:select1>
            </template>
        </metadata>
    </xbl:binding>
</xbl:xbl>

问题是数据项不是从 XML 中获取的,但是如果我在表单结构中引入模板本身,它就可以工作。

有人有什么想法吗?

4

1 回答 1

3

创建 XBL 组件很棘手。至少你第一次这样做。一些东西:

  1. 为避免混淆,我建议您在自己的命名空间中定义组件。在下面的示例中,我使用了xmlns:my="http://www.example.com/".
  2. 的内容fb:template是如何使用组件,而不是它的实现。所以,它应该看起来像:

    <fb:template>
        <my:country-selector>
            <xforms:label ref=""/>
            <xforms:hint ref=""/>
            <xforms:help ref=""/>
            <xforms:alert ref=""/>
        </my:country-selector>
    </fb:template>
    
  3. 实现在里面xbl:template

  4. 所以组件可以在运行时找到,你需要把它放在一个目录xbl/my/country-selector/country-selector.xbl中。通过在 中添加以下属性,将目录的my一部分映射到命名空间properties-local.xml

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

    (通常,我们对目录和前缀使用相同的名称,但它们不需要相同。例如,fr:*组件位于名为 . 的目录中orbeon。)

  5. 因此 Form Builder 在侧边栏中显示您的组件,您需要添加如下属性:

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

这是完整的来源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>
于 2012-12-12T01:35:40.447 回答