• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Table data display with JSTL in a JSP

 
SP Nam
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 <cut> 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
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic