I am trying to display on the console using STAFResult, a marshalled string which has set at least 2 maps, but I didn't managed. When I use one map, the information is organized into a table, but when I use 2 maps and I let the string marshalled, the information is organised as a tree instead of 2 tables:
Example:
public STAFResult acceptRequest(RequestInfo info) {
String ri = info.request.toLowerCase();
StringTokenizer strtokenizer = new StringTokenizer(ri);
String ri1 = strtokenizer.nextToken();
if (ri1.equals("get")) {
STAFMapClassDefinition messageOutputMapClass, testOutputMapClass;
messageOutputMapClass = new STAFMapClassDefinition("STAF/Service/output");
messageOutputMapClass.addKey("status", "STATUS");
messageOutputMapClass.addKey("id", "ID");
testOutputMapClass= new STAFMapClassDefinition("STAF/Service/SCC/test");
testOutputMapClass.addKey("pass", "PASS");
testOutputMapClass.addKey("fail", "FAIL");
testOutputMapClass.addKey("total", "TOTAL");
STAFMarshallingContext mc = new STAFMarshallingContext();
mc.setMapClassDefinition(messageOutputMapClass);
mc.setMapClassDefinition(testOutputMapClass);
ArrayList<ArrayList<Map<String, Object>>> mapsList = new ArrayList<ArrayList<Map<String, Object>>>();
mapsList.add(outputList);
mapsList.add(testList);
mc.setRootObject(mapsList); // the 2 maps are displayed as a tree
//mc.setRootObject(outputList); - when I set root object with outputList (just one map), the table correctly displayed
return new STAFResult(rc,mc.marshall());
}
}
Result:
[
{
STATUS : PASS
ID : 1
}
{
STATUS : PASS
ID : 2
}
{
STATUS : PASS
ID : 3
}
{
STATUS : PASS
ID : 4
}
{
STATUS : PASS
ID : 5
}
{
STATUS : PASS
ID : 6
}
{
STATUS : PASS
ID : 7
}
]
[
{
PASS : 7
FAIL : 0
TOTAL : 7
}
]
and the result should look like:
Additional info
STATUS ID
-------- -
PASS 1
PASS 2
PASS 3
PASS 4
PASS 5
PASS 6
PASS 7
PASS FAIL TOTAL
------ ----- -------
7 0 7
Could you please give me some feedback regarding this issue?
Thanks,
Cristiana
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This section says that marshalled data can be formatted in a tabular form (aka "table format") only if the data is a <List> of <Map:<Class>> where every item in the list is an instance of the same map class. Your data is not like this. For data that is more complex (like your example), or if tables have been turned off, the output will be printed in a hierarchical nested format, called "verbose format".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am trying to display on the console using STAFResult, a marshalled string which has set at least 2 maps, but I didn't managed. When I use one map, the information is organized into a table, but when I use 2 maps and I let the string marshalled, the information is organised as a tree instead of 2 tables:
Example:
public STAFResult acceptRequest(RequestInfo info) {
String ri = info.request.toLowerCase();
StringTokenizer strtokenizer = new StringTokenizer(ri);
String ri1 = strtokenizer.nextToken();
if (ri1.equals("get")) {
STAFMapClassDefinition messageOutputMapClass, testOutputMapClass;
messageOutputMapClass = new STAFMapClassDefinition("STAF/Service/output");
messageOutputMapClass.addKey("status", "STATUS");
messageOutputMapClass.addKey("id", "ID");
testOutputMapClass= new STAFMapClassDefinition("STAF/Service/SCC/test");
testOutputMapClass.addKey("pass", "PASS");
testOutputMapClass.addKey("fail", "FAIL");
testOutputMapClass.addKey("total", "TOTAL");
STAFMarshallingContext mc = new STAFMarshallingContext();
mc.setMapClassDefinition(messageOutputMapClass);
mc.setMapClassDefinition(testOutputMapClass);
ArrayList<Map<String, Object>> outputList = new ArrayList<Map<String,Object>>();
for(int j=1;j<8;j++)
{
Map<String, Object> outputMap = messageOutputMapClass.createInstance();
outputMap.put("status", "PASS" );
outputMap.put("id", j.toString());
outputList.add(outputMap);
}
ArrayList<Map<String, Object>> testList = new ArrayList<Map<String,Object>>();
Map<String, Object> testMap = testMapClass.createInstance();
int intTotalFailed = 0;
int intTotalPassed=7;
int intTotalCount=7;
testMap.put("pass", intTotalPassed);
testMap.put("fail", intTotalFailed);
testMap.put("total", intTotalCount);
testList.add(testMap);
ArrayList<ArrayList<Map<String, Object>>> mapsList = new ArrayList<ArrayList<Map<String, Object>>>();
mapsList.add(outputList);
mapsList.add(testList);
mc.setRootObject(mapsList); // the 2 maps are displayed as a tree
//mc.setRootObject(outputList); - when I set root object with outputList (just one map), the table correctly displayed
return new STAFResult(rc,mc.marshall());
}
}
Result:
[
{
STATUS : PASS
ID : 1
}
{
STATUS : PASS
ID : 2
}
{
STATUS : PASS
ID : 3
}
{
STATUS : PASS
ID : 4
}
{
STATUS : PASS
ID : 5
}
{
STATUS : PASS
ID : 6
}
{
STATUS : PASS
ID : 7
}
]
[
{
PASS : 7
FAIL : 0
TOTAL : 7
}
]
and the result should look like:
Additional info
STATUS ID
-------- -
PASS 1
PASS 2
PASS 3
PASS 4
PASS 5
PASS 6
PASS 7
PASS FAIL TOTAL
------ ----- -------
7 0 7
Could you please give me some feedback regarding this issue?
Thanks,
Cristiana
See section "5.2 STAF" in the STAF User's Guide at http://staf.sourceforge.net/current/STAFUG.htm#HDRSTAFEXECMD for information on how marshalled data is printed in the most appropriate format.
This section says that marshalled data can be formatted in a tabular form (aka "table format") only if the data is a <List> of <Map:<Class>> where every item in the list is an instance of the same map class. Your data is not like this. For data that is more complex (like your example), or if tables have been turned off, the output will be printed in a hierarchical nested format, called "verbose format".