commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Scott Walters" <>
Subject [jelly] define:invokeBody in a loop
Date Mon, 22 Aug 2005 23:09:15 GMT

I tried to write a simple define taglib that uses the sql taglib to generate 
xml from a database.  The code I'm using to call the new tags looks like 

	<sxml:setupQuery tableName="parent_tbl">
		<sxml:bindParams dataValueColumn="ID" bindColumn="ID"/>
			<sxml:setupQuery tableName="child1_tbl">
				<sxml:bindParams dataValueColumn="ID" bindColumn="parent_id"/>

In order to make this work, I coded the <sxml:toxml> tag to  iterate through 
each row in the result set and invoke it's body .  This works great for the 
first iteration of the loop but subsequent iterations don't return any 
output. I suspect this is because the first invokeBody causes the body to be 
removed from the script. Does this make sense?  Is there some other way to 
do this?  The complete taglib is included below.


<?xml version="1.0"?>

<j:jelly xmlns:j="jelly:core" xmlns:sql="jelly:sql"
		xmlns:jxml="jelly:xml" xmlns:define="jelly:define">

	<define:taglib uri="sqlexp">

		<define:tag name="setupQuery">

		<define:tag name="bindParams">
			<j:new var="parmMapTemp" className="java.util.HashMap"/>
			<j:set var="parmMap" value="${parmMapTemp}" scope="parent"/>

			<j:set var="dataValueColumnName" value="${dataValueColumn}" 
			<j:set var="bindColumnName" value="${bindColumn}" scope="parent"/>


		<define:tag name="bindValue">

		<define:tag name="toxml">
			<j:set var="paramVal" 

			<sql:query var="results" trim="false">
				select * from <j:expr value="${tableName}"/> where <j:expr 
value="${bindColumnName}"/>  = ?
				<sql:param value="${paramVal}"/>

			<j:invoke on="${columnNamesStack}" method="push">
				<j:arg type="java.lang.Object" value="${results}"/>

			<j:forEach items="${results.rowsByIndex}" var="row">
					<j:new var="columnMap" className="java.util.HashMap"/>
					<j:forEach var="columnName" 
items="${columnNamesStack.peek().columnNames}" indexVar="i">
						<jxml:element name="${columnName}">
							<j:expr value="${row[i]}"/>
						<j:invoke on="${columnMap}" method="put">
							<j:arg type="java.lang.Object" value="${columnName}"/>
							<j:arg type="java.lang.Object" value="${row[i]}"/>

					<j:invoke on="${paramValues}" method="push">
						<j:arg type="java.lang.Object" value="${columnMap}"/>


					<j:invoke on="${paramValues}" method="pop"/>
			<j:invoke on="${columnNamesStack}" method="pop"/>



On the road to retirement? Check out MSN Life Events for advice on how to 
get there!

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message