问题
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