How to get value from sessionscope in radiogroup for XPages

一曲冷凌霜 提交于 2019-12-11 17:00:59

问题


We have an XPages application that is setup with help of Notes keyword documents. These keywords are made available via sessionScopes. An example of a scope variable is:

name scope: key_customer_sv

values:

default values [Yes, No]

For the values I am using a LinkedHashSet to guarantee the insertion order:

var values:java.util.LinkedHashSet = new java.util.LinkedHashSet();
                        var iterator = keyValues.iterator();                         
                        while (iterator.hasNext()) {
                            var itemvalue = iterator.next();
                            values.add(itemvalue);
                        }                       
                        map.put("values",values);   

The values are stored as as HashMap and the pair names are default and values.

For my xp:radioGroup control I want to read the scope variable and return the values of the value entry.

How must I do this?

Here is what I tried:

var language = "_" + context.getLocaleString();
var languageDefault = "_" + "sv";
var key = "customer";
var values;
try{
    values = sessionScope.get("key_" + key + language )['values'];
}catch(e){
    print(e);
}
if (null == values){
    values = sessionScope.get("key_" + key + language Default)['values'];
}
return values

回答1:


This works for me:

var language = "_" + context.getLocaleString();
var languageDefault = "_" + "sv";
var key = "customer";
var values;
try{
    values = sessionScope.get("key_" + key + language ).get('values');
}catch(e){
    print(e);
}
if (null == values){
    values = sessionScope.get("key_" + key + languageDefault).get('values');
}
return values==null?"":values.toArray();

It is important by getting values using .get('values') instead of ['values'] , because it returns something different.

I tested is by filling sessionScope with this code:

var key_customer_sv:java.util.HashMap = new java.util.HashMap();
var values:java.util.LinkedHashSet = new java.util.LinkedHashSet();
values.add("Yes");
values.add("No");                       
key_customer_sv.put("values",values);
key_customer_sv.put("default", "Yes");
sessionScope.put("key_customer_sv", key_customer_sv)


来源:https://stackoverflow.com/questions/53114869/how-to-get-value-from-sessionscope-in-radiogroup-for-xpages

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