• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Table data display with JSTL in a JSP

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am using JSTL <c:forEach> to iterate rows from a table and display on a page. I need a hyperlink for one column value.

My code is as follows:

<table border="1">
<%-- Get the column names for the header of the table --%>
<c:forEach var="columnName" items="${abc.columnNames}">
<th><c ut value="${columnName}"/></th>
</c:forEach>
<br>

<%-- Get the value of each column while iterating over rows --%>
<c:forEach var="row" items="${abc.rows}">
<tr>
<c:forEach var="column" items="${row}">
<td><c ut value="${column.value}" /></td>
</c:forEach>
</tr>
</c:forEach>
</table>

Any pointers on how to go about it.

SP Nam
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SP, with 35 posts to the Ranch you should know by now to enclose your code in UBB code tags (you can enter them by hand or use the CODE button below the topic entry area), and to click the 'disable smilies' checkbox to keep your <c:out> tags from looking so surprised.

With regards to your question, you create a link using an <a> tag just like in any other page. The rules of HTML don't change just because you are generating the page with JSP/JSTL.
[ October 27, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It also looks like you forgot the <tr> tag to enclose the first row of <th> tags.
 
SP Nam
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear
I need <a> tag for one column value, when I put <a> with my code it is taking hyper link for all values.

Any code snippet Please

SP Nam
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As stated earlier by Bear, using the anchor tag in a JSP page is no different than a normal html web page.

Each anchor tag must be terminated with a </a> tag.

For example
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it is taking hyper link for all values.



If I am understanding this correctly -- which I may not be -- you are saying that you only want certain rows to be links based upon some criteria?

If so, then think of it just the same as you would a similiar issue in Java. If you are iterating through some data, and want to take special action only under certain conditions, then you would test for that condition using an if statement. Same deal applies here: use <c:if> to determine when to include the link markup.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic