Clarity

 View Only
  • 1.  How to dump/print array key=>value info?

    Posted Aug 18, 2014 11:43 AM

    I'm trying to output the key=>value pairs of an array but not getting any info. It seems to be looping through the array but not printing anything. I found the following in another post to du mp all the context vars but I'm trying to limit it to a specific array:

    <core:forEach var="entry" items="${q_weights.rows}"> 
      <gel:log level="INFO" category="DEBUG" var="include_log"> ${entry.getKey()} = ${entry.getValue()} |  ${entry.getValue().getClass().getName()} </gel:log>  
    </core:forEach>
    

    But all I get is:

    [DEBUG] = | 
    

    Right now I'm just trying to log the info as a concept, but long term my thinking is to make this a standalone file with the array as a variable I would set in my main script (an SQL result more than likely, with updated values), then use this to loop through the results to create an element for a XOG. Something like:

     

    <ColumnValue name="${key}">${value}</ColumnValue>
    
    

    which would then be included in an overall XOG call



  • 2.  Re: How to dump/print array key=>value info?
    Best Answer

    Posted Aug 18, 2014 12:33 PM

    queryResults.rows gives you a SortedMap containing TreeMaps so each item is a java.util.TreeMap.

     

    <gel:log message="By java.util.TreeMap" />
    <core:forEach var="row" items="${queryResults.rows}">
        <gel:log message="${row.getClass().getName()}" />
        <core:forEach var="key" items="${row.keySet()}" >
            <gel:log level="INFO" var="include_log"> ${key} = ${row.get(key)} |  ${row.getValue().getClass().getName()} </gel:log>   
        </core:forEach>              
    </core:forEach>
    

     

    V/r,

    Gene



  • 3.  Re: How to dump/print array key=>value info?

    Posted Aug 18, 2014 12:42 PM

    By rowByIndex:

     

    <core:set var="columnNames" value="${queryResults.getColumnNames()}" />
    <core:forEach trim="true" items="${queryResults.rowsByIndex}" var="row">
            <core:forEach var="columnName" items="${columnNames}" indexVar="i">
                <gel:out>${columnName} = ${row[i]}</gel:out>
            </core:forEach>               
    </core:forEach>
    

    V/r,

    Gene



  • 4.  Re: How to dump/print array key=>value info?

    Posted Aug 18, 2014 01:18 PM

    Worked like a charm. Keep forgetting these things are all basically just Java objects and we can use whatever methods they have available