How to get value from sessionscope in radiogroup f

2019-08-19 13:20发布

问题:

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)