File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Table data display with JSTL in a JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Table data display with JSTL in a JSP" Watch "Table data display with JSTL in a JSP" New topic
Author

Table data display with JSTL in a JSP

SP Nam
Ranch Hand

Joined: Oct 15, 2003
Posts: 41
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

Joined: Jan 10, 2002
Posts: 60782
    
  65

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

It also looks like you forgot the <tr> tag to enclose the first row of <th> tags.
SP Nam
Ranch Hand

Joined: Oct 15, 2003
Posts: 41
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

Joined: Mar 19, 2002
Posts: 405
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

Joined: Jan 10, 2002
Posts: 60782
    
  65

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Table data display with JSTL in a JSP
 
Similar Threads
JSTL c:out as HTML, how?
HTML table
design problem
sql:query in jsp
Convert JSTL variable type