JSTL forEach

B

Bob Rivers

Hi,

I'm new to JSTL, and I'm trying to understand the forEach interator.

Looking through the example provided (jstl-standard-examples.war)

<c:forEach var="customer" items="${customers}">
<c:eek:ut value="${customer}"/><br>
</c:forEach>

The output is someting like this:

[1] Richard, Maurice 05/15/1935 123 Chemin Royal Montreal Canada
[2] Mikita, Stan 12/25/1947 45 Fisher Blvd Chicago USA (320)876-9784

Ok, no problem. customers is a Vector of customer objects.

How do I get a specific value of the vector? Let's say that I want to
print only the birthdate? Or, what if I want to put each value inside
a table colunm (ex.: <td>name</td><td>birthdate</td>...).

TIA,

Bob
 
T

Tim Slattery

Hi,

I'm new to JSTL, and I'm trying to understand the forEach interator.

Looking through the example provided (jstl-standard-examples.war)

<c:forEach var="customer" items="${customers}">
<c:eek:ut value="${customer}"/><br>
</c:forEach>

The output is someting like this:

[1] Richard, Maurice 05/15/1935 123 Chemin Royal Montreal Canada
[2] Mikita, Stan 12/25/1947 45 Fisher Blvd Chicago USA (320)876-9784

Ok, no problem. customers is a Vector of customer objects.

How do I get a specific value of the vector? Let's say that I want to
print only the birthdate? Or, what if I want to put each value inside
a table colunm (ex.: <td>name</td><td>birthdate</td>...).

Presumably each member of the customers collection is an object that
has accessor methods for its properties. That being the case, you code
something like this to get the two table cells you mention above:

<td><c:eek:ut value="${customer.name}"/></td><td><c:eek:ut
value="${customer.birthdate}"/></td>

The accessor methods "getName" and "getBirthdate" of the customer
object will be called.
 
T

The Abrasive Sponge

Tim said:
Hi,

I'm new to JSTL, and I'm trying to understand the forEach interator.

Looking through the example provided (jstl-standard-examples.war)

<c:forEach var="customer" items="${customers}">
<c:eek:ut value="${customer}"/><br>
</c:forEach>

The output is someting like this:

[1] Richard, Maurice 05/15/1935 123 Chemin Royal Montreal Canada
[2] Mikita, Stan 12/25/1947 45 Fisher Blvd Chicago USA (320)876-9784

Ok, no problem. customers is a Vector of customer objects.

How do I get a specific value of the vector? Let's say that I want to
print only the birthdate? Or, what if I want to put each value inside
a table colunm (ex.: <td>name</td><td>birthdate</td>...).


Presumably each member of the customers collection is an object that
has accessor methods for its properties. That being the case, you code
something like this to get the two table cells you mention above:

<td><c:eek:ut value="${customer.name}"/></td><td><c:eek:ut
value="${customer.birthdate}"/></td>

The accessor methods "getName" and "getBirthdate" of the customer
object will be called.

But dates a best used with <fmt> than a <c:eek:ut>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top