[jelly] define:invokeBody in a loop

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[jelly] define:invokeBody in a loop

Scott Walters

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"/>



Is your PC infected? Get a FREE online computer virus scan from McAfee?
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]