Xpages 获取列表框的选定值?

Xpages 获取列表框的选定值?,xpages,Xpages,如何获取所选项目是列表、组合框等 我发现了以下代码: /***** ***getSelectableValues() ***打印给定组件的所有可选值,例如组合框、列表框等。 *** ***@params组件的id *****/ 函数getSelectableValues(id){ var ComboBox=getComponent(id); var ChildrenList:java.util.ListIterator; ChildrenList=ComboBox.getChildren().l

如何获取所选项目是列表、组合框等

我发现了以下代码:

/*****
***getSelectableValues()
***打印给定组件的所有可选值,例如组合框、列表框等。
***
***@params组件的id
*****/
函数getSelectableValues(id){
var ComboBox=getComponent(id);
var ChildrenList:java.util.ListIterator;
ChildrenList=ComboBox.getChildren().listIterator();
while(ChildrenList.hasNext()){
var Child=ChildrenList.next();
/***进程计算/多个值***/
if(typeof(Child)='com.ibm.xsp.component.UISelectItemsEx'){
var hlp=Child.getValue();
对于(变量i=0;i

但它似乎得到了列表框中的所有项目,而不仅仅是选定的项目。您知道如何修改它以仅获取选定值吗?

您可以使用SSJS访问选定值:

getComponent('comboBox1').value
如果正在使用列表框,并且启用了“多选”,则可以使用“分解”获取字符串数组:

@Explode(getComponent('listBox1').value)

询问数据模型,而不是询问组件。例如,如果列表框绑定到:

#{someDoc.someItemName}
…然后您可以通过询问数据源来检索所选值:

var selectedValues = someDoc.getValue("someItemName");
如果组件被绑定到一个作用域变量:

#{viewScope.selectedValues}
var selectedValues = viewScope.get("selectedValues");
…然后只需询问该变量:

#{viewScope.selectedValues}
var selectedValues = viewScope.get("selectedValues");

如果长方体附加到数据模型,则这是更好的方法