Friday, September 19, 2008

FatWire - dump all ICS variables

Often I get stuck in some element code or whatever, where the ICS variable I think is there, turns out not to be there. Rather than guess, it is often useful just to output all of the variables first and see if your variable is there but perhaps under a different name. Here is the code I use to dump out all the ICS variables for inspection.

In JSP, output the ICS variable names.

<div style="color: red">List ICS var names.</div>
<ul>
<%
java.util.Enumeration varNames = ics.GetVars();
while (varNames.hasMoreElements()) {
   %>
   <li><%= varNames.nextElement().toString() %></li>
   <%
}
%>
</ul>

In JSP, output the ICS variable names and values.

<div style="color: red">List ICS var names and values.</div>
<table border="1">
    <tr><th>Name</th><th>Value</th></tr>
    <%
    java.util.Enumeration varNames = ics.GetVars();
    while (varNames.hasMoreElements()) {
        String nextName = varNames.nextElement().toString();
        %><tr>
            <td><%= nextName %></td>
            <td><%= ics.GetVar(nextName) %></td>
        </tr><%
    }
    %>
</table>

In Java, output the ICS variable names and values.

java.util.Enumeration varNames = ics.GetVars();
while (varNames.hasMoreElements()) {
    String elementName = varNames.nextElement().toString();
    System.out.println("Element name  [" + elementName + "] with value  [" +
            ics.GetVar(elementName) + "].");
}