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 Thomas Forrester <tf...@dbconcert.com> on 2004/03/12 12:45:05 UTC

How to populate a FORM List object in template text for N results


How do I write out template HTML to populate a FORM LIST object, from a
SQL query result set.

For example:

<sql:query var="clientResult" scope="page">
        	select CLIENT_NAME from CLIENT
</sql:query>

// Now given that I don't know how many rows I will get back, I can't
write out N number of <option value=... Lines, and if I use a forEach
loop they will just get overwritten.
<form name="form1" method="post" action="">
  <select name="select">
    <option value="firstValue">firstLabel</option>
    <option value="secondLable" selected>secondLabel</option>
    <option value="thiredValue">thirdLabel</option>
  </select>
</form>

Now given that I don't know how many rows I will get back, I can't write
out N number of <option value=... Lines, and if I use a forEach loop
they will just get overwritten.

What is the technique to use here, or is there a special tag that will
do this?



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


RE: How to populate a FORM List object in template text for N results

Posted by Martin van Dijken <su...@windgazer.nl>.
Hey Thomas,

What exactly is the problem with using forEach? It simply loops an iterator,
map, array or collection and displays it's body content while it has results
left.

<c:forEach items="${clientResult}" var="row">
	<option value="<c:out value="${row.value}"/>"><c:out
value="${row.text}"/></option>
</c:forEach>

Replace row.value and row.text with the access method for the variable in
the row you're trying to dump.

Martin

-----Oorspronkelijk bericht-----
Van: Thomas Forrester [mailto:tforrester@dbconcert.com]
Verzonden: vrijdag 12 maart 2004 12:45
Aan: taglibs-user@jakarta.apache.org
Onderwerp: How to populate a FORM List object in template text for N
results




How do I write out template HTML to populate a FORM LIST object, from a
SQL query result set.

For example:

<sql:query var="clientResult" scope="page">
        	select CLIENT_NAME from CLIENT
</sql:query>

// Now given that I don't know how many rows I will get back, I can't
write out N number of <option value=... Lines, and if I use a forEach
loop they will just get overwritten.
<form name="form1" method="post" action="">
  <select name="select">
    <option value="firstValue">firstLabel</option>
    <option value="secondLable" selected>secondLabel</option>
    <option value="thiredValue">thirdLabel</option>
  </select>
</form>

Now given that I don't know how many rows I will get back, I can't write
out N number of <option value=... Lines, and if I use a forEach loop
they will just get overwritten.

What is the technique to use here, or is there a special tag that will
do this?



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