tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/65-adding-values-to-an-arraylist-with-addCascade CMS: Discussion 2014-08-20T15:05:19Ztag:help-archives.hannonhill.com,2010-02-09:Comment/114405762011-11-15T22:19:43Z2011-11-15T22:20:48ZAdding values to an arrayList with add()<div><p>Glenn,</p>
<p>To answer your question, yes, there is a way to make the
$list.add() call without it being rendered by the Velocity script,
and that is to make the call from within a #set() directive, like
so:</p>
<pre>
<code>#set ( $success = $myList.add($someVal) )</code>
</pre>
<p>Note: the <code>add()</code> method returns a boolean indicating
the success (or failure) of the add action.</p>
<p>However, for your specific case, this added step of creating
another list is unnecessary, as
<code>$_XPathTool.selectNodes()</code> already returns a List
object. The problem you are having with using
<code>$_DisplayTool.list()</code> can be rectified by simply
telling the <code>list()</code> method what specific property of
the List objects you wish to output. In your case, it appears you
want to output the <code>value</code> property. So, you should be
able to do something like this:</p>
<pre>
<code>#set ($committees = $_XPathTool.selectNodes($contentRoot, "committees"))
${_DisplayTool.list($committees,"; ","; ","value")}</code>
</pre>
<p>Note that in the above call, I've passed 2 additional arguments
to the <code>list()</code> method. The arguments are as
follows:</p>
<p>1) The List of objects to be displayed.<br>
2) The delimiter to use between each object<br>
3) The delimiter to use before the <em>final</em> object (can be
different from the others, if desired)<br>
4) The name of the property to display for each List object</p>
<p>In your case, by passing in "value" as argument <a href=
"/discussions/velocity-formats/4" title="Discussion #4">#4</a>, you
should be able to use the <code>$_DisplayTool.list()</code> method
directly on the original <code>$committees</code> List without
having to create the second List.</p>
<p>Hope this helps,</p>
<p>-Brent</p></div>Brent Arringtontag:help-archives.hannonhill.com,2010-02-09:Comment/114405762011-11-15T22:34:23Z2011-11-15T22:34:23ZAdding values to an arrayList with add()<div><p>You know, I <em>thought</em> selectNodes() returned a list
object and that I could just use that. I didn't know about those
other two parameters to <code>$_DisplayTool.list()</code> so it was
just rendering as "[Element]".</p>
<p>Am I limited to simple properties like <code>value</code>? I'd
really like to use the <code>$_EscapeTool</code> on the values
before listing them.</p></div>Shivtag:help-archives.hannonhill.com,2010-02-09:Comment/114405762011-11-15T22:38:53Z2011-11-15T22:38:53ZAdding values to an arrayList with add()<div><p>I think the best way to handle that would be to just escape the
entire output of the <code>list()</code> method at once, like
so:</p>
<pre>
<code>${_EscapeTool.xml($_DisplayTool.list($committees,"; ","; ","value"))}</code>
</pre></div>Brent Arringtontag:help-archives.hannonhill.com,2010-02-09:Comment/114405762011-11-15T22:40:01Z2011-11-15T22:40:01ZAdding values to an arrayList with add()<div><p>Ah, of course.</p>
<p>Thanks for the help! This will be a big time saver.</p></div>Shivtag:help-archives.hannonhill.com,2010-02-09:Comment/114405762011-11-15T22:41:14Z2011-11-15T22:41:14ZAdding values to an arrayList with add()<div><p>No problem. Glad to help!</p></div>Brent Arrington