checkboxgroup returning only last selected value

倖福魔咒の 提交于 2019-12-11 08:00:00

问题


I have a repeat control and populating a checkboxgroup with items from a viewScope array. Sample code is :

<xp:repeat id="repeat4" rows="100" value="#{viewScope.choices}"
    indexVar="rownumber" var="row" first="0">

    <xp:checkBoxGroup id="checkBoxGroup2" layout="lineDirection">
        <xp:selectItems>
            <xp:this.value><![CDATA[#{javascript:if (viewScope.choices[rownumber].get(1)==viewScope.line){
            return viewScope.choices[rownumber].get(0)
           }}]]></xp:this.value>
        </xp:selectItems>
    </xp:checkBoxGroup>
    <xe:tooltip id="tooltip1" for="checkBoxGroup2">
        <xe:this.label><![CDATA[#{javascript:return viewScope.choices[rownumber].get(1)}]]></xe:this.label>
    </xe:tooltip>
</xp:repeat>

I'm reading the checked values with : @Text(getComponent("checkBoxGroup2").getSubmittedValue());

The problem is that it seems I can only read the last selected/ deselected value this way.

I guess it has something to do with the selecteditems that isn't returning an array, but how can I return an array with the given data ?


回答1:


You can't use checkBoxGroup in this case. Every checkBoxGroup created by repeat is an own control and they are not connected to each other.

Use a simple checkBox control instead and write the selected values in view scope variable array:

<xp:this.beforePageLoad><![CDATA[#{javascript:
    if (!viewScope.selected) {
        viewScope.selected = new Array(viewScope.choices.length);
    }
}]]></xp:this.beforePageLoad>
<xp:repeat
    id="repeat4"
    rows="100"
    value="#{javascript:viewScope.choices}"
    indexVar="rownumber"
    var="row"
    first="0">
    <xp:panel
        id="panelCheckBox"
        style="display: inline-block;">
        <xp:checkBox
            id="checkBox1"
            text="#{row[0]}"
            value="#{viewScope.selected[rownumber]}"
            checkedValue="#{row[0]}"
            uncheckedValue="#{javascript:''}" />
    </xp:panel>
    <xe:tooltip
        id="tooltip1"
        for="panelCheckBox"
        position="below"
        label="#{row[1]}" />
</xp:repeat>

The result is in viewScope.selected then.



来源:https://stackoverflow.com/questions/42416359/checkboxgroup-returning-only-last-selected-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!