You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by ea...@sprintmail.com on 2003/10/04 06:52:48 UTC
sql:query to an ArrayList
HI all,
I am trying to figure out how to go from <sql:query var="rs"
scope="page" dataSource="${conn}"> ... to an ArrayList that I need to
feed to another taglib. I've looked through the Hans' JavaServer
Pages book and found something that looked like it should work:
<%
ArrayList testList = new ArrayList();
%>
<c:forEach items="${rs.rows}" var="row" varStatus="status">
<c:set var="partNum" value="${row.PartNumber}"/>
<%
String partNumber = (String) pageContext.getAttribute("partNum");
testList.add( partNumber );
%>
</c:forEach>
<%
request.setAttribute( "testList", testList );
%>
<display:table name="testList" class="its"/>
However, the page is truncated before it even appears to run this
code (last line is "<td>00008")? If I delete the scriptlet in the
middle of the forEach loop the page displays properly with display
tag saying that it is empty... I also tried using:
<jsp:useBean id="partNum" class="java.lang.String"/>
<%
testList.add( partNum );
%>
and got the same weird truncation.
I'd appreciate some help on going from the sql tag's row collection
to an ArrayList.
Thanks,
Eric
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: sql:query to an ArrayList
Posted by Henri Yandell <ba...@generationjava.com>.
You can use the Xephryus Data Structures Taglib here, rather than dropping
down into Java.
http://www.xephyrus.com/taglib-datastructs/
I've been very happily using it on a simple JSP-only system [well,
JSP-only and JavaBeans because JSTL cannot treat Maps as beans
*grumblegrumble*].
If interested, I can send the example code of taking sql into lists next
week [code is at work].
Hen
On Sat, 4 Oct 2003, Serge Knystautas wrote:
> Why do you need it as an ArrayList? Generally it's bad practice to
> reference objects by interface, not implementation. But anyway, to get
> to List...
>
> <c:set var="rows" value="${rs.rows}" />
> <%
> Object[] rows = (Object[]) pageContext.findAttribute("rows");
> List testList = Arrays.asList(rows);
> %>
>
> --
> Serge Knystautas
> President
> Lokitech >>> software . strategy . design >> http://www.lokitech.com
> p. 301.656.5501
> e. sergek@lokitech.com
>
> earnst@sprintmail.com wrote:
> > HI all,
> > I am trying to figure out how to go from <sql:query var="rs"
> > scope="page" dataSource="${conn}"> ... to an ArrayList that I need to
> > feed to another taglib. I've looked through the Hans' JavaServer
> > Pages book and found something that looked like it should work:
> >
> > <%
> > ArrayList testList = new ArrayList();
> > %>
> >
> > <c:forEach items="${rs.rows}" var="row" varStatus="status">
> > <c:set var="partNum" value="${row.PartNumber}"/>
> > <%
> > String partNumber = (String) pageContext.getAttribute("partNum");
> > testList.add( partNumber );
> > %>
> > </c:forEach>
> >
> > <%
> > request.setAttribute( "testList", testList );
> > %>
> >
> > <display:table name="testList" class="its"/>
> >
> > However, the page is truncated before it even appears to run this
> > code (last line is "<td>00008")? If I delete the scriptlet in the
> > middle of the forEach loop the page displays properly with display
> > tag saying that it is empty... I also tried using:
> >
> > <jsp:useBean id="partNum" class="java.lang.String"/>
> > <%
> > testList.add( partNum );
> > %>
> >
> > and got the same weird truncation.
> >
> > I'd appreciate some help on going from the sql tag's row collection
> > to an ArrayList.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
Re: sql:query to an ArrayList
Posted by Serge Knystautas <se...@lokitech.com>.
Why do you need it as an ArrayList? Generally it's bad practice to
reference objects by interface, not implementation. But anyway, to get
to List...
<c:set var="rows" value="${rs.rows}" />
<%
Object[] rows = (Object[]) pageContext.findAttribute("rows");
List testList = Arrays.asList(rows);
%>
--
Serge Knystautas
President
Lokitech >>> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com
earnst@sprintmail.com wrote:
> HI all,
> I am trying to figure out how to go from <sql:query var="rs"
> scope="page" dataSource="${conn}"> ... to an ArrayList that I need to
> feed to another taglib. I've looked through the Hans' JavaServer
> Pages book and found something that looked like it should work:
>
> <%
> ArrayList testList = new ArrayList();
> %>
>
> <c:forEach items="${rs.rows}" var="row" varStatus="status">
> <c:set var="partNum" value="${row.PartNumber}"/>
> <%
> String partNumber = (String) pageContext.getAttribute("partNum");
> testList.add( partNumber );
> %>
> </c:forEach>
>
> <%
> request.setAttribute( "testList", testList );
> %>
>
> <display:table name="testList" class="its"/>
>
> However, the page is truncated before it even appears to run this
> code (last line is "<td>00008")? If I delete the scriptlet in the
> middle of the forEach loop the page displays properly with display
> tag saying that it is empty... I also tried using:
>
> <jsp:useBean id="partNum" class="java.lang.String"/>
> <%
> testList.add( partNum );
> %>
>
> and got the same weird truncation.
>
> I'd appreciate some help on going from the sql tag's row collection
> to an ArrayList.
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org