获取XForm中重复内部的单选按钮的值

时间:2013-10-08 14:59:00

标签: orbeon xforms

我在XForms中遇到一些重复问题。我需要访问循环内的单选按钮字段的某些值。范围是在单选按钮选择了特定值时使输入文本可见。我希望所有重复都有这种行为(单选按钮和输入文本字段在循环内)。

它适用于一行,但是当我添加一个新行时,代码不再起作用。

我复制一个简单的例子来检查这种行为:

<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:odt="http://orbeon.org/oxf/xml/datatypes"
     xmlns:oxf="http://www.orbeon.com/oxf/processors"
     xmlns:p="http://www.orbeon.com/oxf/pipeline"
     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:xpl="java:org.orbeon.oxf.pipeline.api.FunctionLibrary"
     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>Loop</xh:title>
    <xf:model id="fr-form-model" xxf:expose-xpath-types="true">
        <xf:instance xxf:readonly="true" id="fr-form-metadata">
            <metadata>
                <application-name>DHszw</application-name>
                <form-name>Loop</form-name>
                <title xml:lang="en">Loop</title>
                <description xml:lang="en">Description of the form.</description>
            </metadata>
        </xf:instance>
        <xf:instance id="fr-form-instance">
            <form>
                <category-1>
                    <subcategory-1-1/>
                    <element-1-1-1/>
                    <loop-group-0>
                        <loop-0>
                            <element-1-1-2/>
                            <element-1-1-3/>
                        </loop-0>
                    </loop-group-0>
                    <element-1-1-4/>
                    <element-1-1-5/>
                </category-1>
            </form>
        </xf:instance>
        <xf:bind xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel" id="fr-form-binds"
                 ref="instance('fr-form-instance')">
            <xf:bind id="category-1-bind" name="category-1" ref="category-1">
                <xf:bind id="subcategory-1-1-bind" name="subcategory-1-1" ref="subcategory-1-1"/>
                <xf:bind id="element-1-1-1-bind" name="element-1-1-1" ref="element-1-1-1"/>
                <xf:bind id="group-loop-0-bind" name="group-loop-0-bind" ref="loop-group-0"
                         relevant="($element-1-1-1='yes' )">
                    <xf:bind id="loop-0-bind" name="loop-0" ref="loop-0" relevant="($element-1-1-1='yes' )">
                        <xf:bind id="element-1-1-2-bind" name="element-1-1-2" ref="element-1-1-2"
                                 relevant="($element-1-1-1='yes' )"/>
                        <xf:bind id="element-1-1-3-bind" name="element-1-1-3" ref="element-1-1-3"
                                 relevant="($element-1-1-2='yes' )"/>
                    </xf:bind>
                </xf:bind>
                <xf:bind id="element-1-1-4-bind" name="element-1-1-4" ref="element-1-1-4"
                         relevant="($element-1-1-1='no' ) or ($element-1-1-2='no' )"/>
                <xf:bind id="element-1-1-5-bind" name="element-1-1-5" ref="element-1-1-5"
                         relevant="($element-1-1-1='no' ) or ($element-1-1-2='no' )"/>
            </xf:bind>
        </xf:bind>
        <xf:instance id="fr-form-attachments">
            <attachments>
                <css filename="" mediatype="text/css" size=""/>
                <pdf filename="" mediatype="application/pdf" size=""/>
            </attachments>
        </xf:instance>
        <xf:instance id="fr-form-resources" xxf:readonly="false">
            <resources>
                <resource xml:lang="en">
                    <category-1>
                        <label>LoopCategory</label>
                    </category-1>
                    <subcategory-1-1>
                        <label>&lt;b&gt;BasicSubcategory&lt;/b&gt;&lt;hr&gt;</label>
                        <hint/>
                        <alert/>
                    </subcategory-1-1>
                    <element-1-1-1>
                        <label>Do you want a loop?</label>
                        <hint/>
                        <alert/>
                        <item>
                            <label>yes</label>
                            <value>yes</value>
                        </item>
                        <item>
                            <label>no</label>
                            <value>no</value>
                        </item>
                    </element-1-1-1>
                    <element-1-1-2>
                        <label>Do you want an Input Text?</label>
                        <hint>More</hint>
                        <alert/>
                        <item>
                            <label>yes</label>
                            <value>yes</value>
                        </item>
                        <item>
                            <label>no</label>
                            <value>no</value>
                        </item>
                    </element-1-1-2>
                    <element-1-1-3>
                        <label>Your input text</label>
                        <hint/>
                        <alert/>
                    </element-1-1-3>
                    <element-1-1-4>
                        <label>Why no loop?</label>
                        <hint/>
                        <alert/>
                    </element-1-1-4>
                    <element-1-1-5>
                        <label>End:</label>
                        <hint/>
                        <alert/>
                    </element-1-1-5>
                </resource>
            </resources>
        </xf:instance>
        <xf:instance id="fr-service-request-instance" xxf:exclude-result-prefixes="#all">
            <response/>
        </xf:instance>
        <xf:instance xxf:readonly="true" id="loop-0-template">
            <loop-0>
                <element-1-1-2/>
                <element-1-1-3/>
            </loop-0>
        </xf:instance>
    </xf:model>
</xh:head>
<xh:body>
    <fr:view>
        <fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
                 xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel">
            <fr:section bind="category-1-bind" id="category-1-control">
                <xf:label ref="$form-resources/category-1/label"/>
                <xh:tr>
                    <xh:td>
                        <xf:output bind="subcategory-1-1-bind" id="subcategory-1-1-control">
                            <xf:label mediatype="text/html" ref="$form-resources/subcategory-1-1/label"/>
                            <xf:hint ref="$form-resources/subcategory-1-1/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>
                        </xf:output>
                    </xh:td>
                </xh:tr>
                <xh:tr>
                    <xh:td>
                        <xf:select1 appearance="full" bind="element-1-1-1-bind" id="element-1-1-1-control">
                            <xf:label ref="$form-resources/element-1-1-1/label"/>
                            <xf:hint ref="$form-resources/element-1-1-1/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>
                            <xf:itemset ref="$form-resources/element-1-1-1/item">
                                <xf:label ref="label"/>
                                <xf:value ref="value"/>
                            </xf:itemset>
                        </xf:select1>
                    </xh:td>
                </xh:tr>
                <xf:group bind="group-loop-0-bind" id="group-loop-0-control">
                    <fr:grid bind="loop-0-bind" id="loop-0-control" max="10" min="1"
                             origin="instance('loop-0-template')"
                             repeat="true">
                        <xh:tr>
                            <xh:td>
                                <xf:select1 appearance="full" bind="element-1-1-2-bind" id="element-1-1-2-control">
                                    <xf:label ref="$form-resources/element-1-1-2/label"/>
                                    <xf:hint ref="$form-resources/element-1-1-2/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                    <xf:itemset ref="$form-resources/element-1-1-2/item">
                                        <xf:label ref="label"/>
                                        <xf:value ref="value"/>
                                    </xf:itemset>
                                </xf:select1>
                            </xh:td>
                        </xh:tr>
                        <xh:tr>
                            <xh:td>
                                <xf:input bind="element-1-1-3-bind" id="element-1-1-3-control">
                                    <xf:label ref="$form-resources/element-1-1-3/label"/>
                                    <xf:hint ref="$form-resources/element-1-1-3/hint"/>
                                    <xf:alert ref="$fr-resources/detail/labels/alert"/>
                                </xf:input>
                            </xh:td>
                        </xh:tr>
                    </fr:grid>
                </xf:group>
                <xh:tr>
                    <xh:td>
                        <xf:input bind="element-1-1-4-bind" id="element-1-1-4-control">
                            <xf:label ref="$form-resources/element-1-1-4/label"/>
                            <xf:hint ref="$form-resources/element-1-1-4/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>
                        </xf:input>
                    </xh:td>
                </xh:tr>
                <xh:tr>
                    <xh:td>
                        <xf:input bind="element-1-1-5-bind" id="element-1-1-5-control">
                            <xf:label ref="$form-resources/element-1-1-5/label"/>
                            <xf:hint ref="$form-resources/element-1-1-5/hint"/>
                            <xf:alert ref="$fr-resources/detail/labels/alert"/>
                        </xf:input>
                    </xh:td>
                </xh:tr>
            </fr:section>
        </fr:body>
    </fr:view>
</xh:body>

如果此代码在Orbeon服务器中运行,它将正常工作,直到我们在'repeat'元素中添加新行。然后,无论在单选按钮中选择的值如何,输入字段都会消失(或不可见)。

我想,添加行的副本,可能会有相同的元素名称(或更改原始元素名称)并导致此问题。但我需要访问每行的单选按钮的值。可能吗?这是一个已知的bug吗?怎么能实现这个目标?

1 个答案:

答案 0 :(得分:1)

您可以使用元素的相对路径而不是bind变量来引用repeat中的元素值,因此在您的情况下:

替换:

($element-1-1-2='yes' )

(../element-1-1-2='yes')

另见orbeon calculated fields in a repeat break after first itiration

这在重复之外不起作用;我不确定你在第二个元素1-1-2条件中的预期逻辑。

此致

Jez的