How to pass JavaScript array to XPages Java controller

I am working with jQuery DataTables. I have a list from the list and checkboxes for selecting multiple documents. I can get the selected keys in the session area using this client side JavaScript code:

<xp:this.script><![CDATA[// Build array of selected rows
var myTableApi = x$("inventoryTable").DataTable();
var count = myTableApi.rows( { selected: true } ).count();
var dataArr = [];
var rowData = myTableApi.rows( { selected: true } ).data();
    $.each($(rowData),function(key,value){
        dataArr.push(value[3]);
    });

// Push that to the requestScope
setScopeValue("session", "rowCount", count);
setScopeValue("session", "rowIds", dataArr);]]></xp:this.script>

Once the identifier is in scope, I change the pages and then I want to load them into my Java Controller page.

I can easily use the resolver variable to get "rowIds". But I'm not sure how to get it in Java so that I can work with it. Ideally, I would like it to be a list or set or something similar.

In Java, how can I convert this javascript array to a collection based object?

Thank!

+4
1

.

-, setScopeValue , setScopeValue("session", "rowIds", XSP.toJson(dataArr)). , , , ["foo", "bar", "baz"] foobarbaz.

-, Session-scoped Java ExtLibUtil.getSessionScope().get("rowIds").

, , JSON. IBM Commons JSON, :

List<?> rowIds = (List<?>)JsonParser.fromJson(JsonJavaFactory.instance, ExtLibUtil.getSessionScope().get("rowIds"))
for(Object rowIdObj : rowIds) {
    String rowId = StringUtil.toString(rowIdObj);
    // do stuff with each ID here
}

List<String>, Java- , , , ClassCastException, List .

+4

All Articles