I'm trying to code some groovy string manipulation of database-extracted
data.
I can't post the actual code but it goes along these lines:

#set ($mydb=$xwiki.sql.getDatabase("jdbc/ABC"))
#set ($SQLstring = "select mycol from fw_notifiche")

#foreach($row in $mydb.executeQuery($SQLstring))
  #set ($mycol = $row.getString("mycol"))

  <%
  vcontext = context.get("vcontext");
  mycol = vcontext.get("mycol");
  newmycol = mycol.replaceAll("2", "two");
  vcontext.put("newmycol", newmycol);
  %>

  Here is the data: $newmycol <br>
#end

The problem is that only the each loop receives the processing of the vary
last row.
Let's say the the loop extracts three rows with values 1, 2, 3. The previous
code results in this output:
3
3
3
(i.e. unreplaced value from the last row)
While if I switch to mycol.replaceAll("3", "three"), the output is:
three
three
three
(i.e. each loop gets the replaced value from the last row)

Seems that velocity and groovy are incorrectly linked thru the context, or
what?

Cheers,
Stefano
-- 
View this message in context: 
http://n2.nabble.com/Context-variables-vs--foreach-tp1300473p1300473.html
Sent from the XWiki- Users mailing list archive at Nabble.com.

_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to