aspose file tools*
The moose likes JSP and the fly likes Problem displaying a dynamic table on a JSP.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem displaying a dynamic table on a JSP...." Watch "Problem displaying a dynamic table on a JSP...." New topic
Author

Problem displaying a dynamic table on a JSP....

Gabriel Fox
Ranch Hand

Joined: Oct 17, 2001
Posts: 170
I am removing some items from a List and using these to generate a table just below the List on a JSP.
The problem is when the number of rows grows over a certain number , table goes all the way down.On using an IFrame and concatenating each of my table rows into a string.And calling a JavaScript function to populate the IFrame on loading the page.
The problem was i cannot maintain the already entered values on my table (a row contains a checkbox,a text,a textbox).
Question: How do i keep my dynamic table in a scrollable Pane(Just like the Javaranch Message box) and maintain the existing
entries on the table when additional rows are added from the list.What is the best way to use.
All ideas and codes are welcomed.
Cheers.
Abhinav Sharma
Greenhorn

Joined: Aug 08, 2001
Posts: 25
Hi gabby,
I don't know what do you mean to say by scrollabale table. But if you are looking for something like javaranch box then i have made a file which is very much similar to this. Only difference is here you specifies rows which you cannot enter more than 15 but may be you can get some idea from my code. I have used the table to make database connectivity. In that i i have shows all the datas in table and no matter how much rows i insert the size of the table keeps on increasing. Anyway here is my code.
<%@ page errorPage="error.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Generating Table </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY bgcolor=#FFCCFF>
<center>
<h1><font color="red">Colorful and Dynamic Table</font></h1>
<form method=post action="Table.jsp">
<table>
<tr>
<td colspan="2"> <font size="2">
<%
int width=15;
int height=15;
%>
<font face="Arial, Helvetica, sans-serif"><b>Table width (Less than
16) =</b>
<input type=text name=width value=<%=width%> size=2>
, </font></font></td>
</tr>
<tr>
<td colspan="2"> <b><font face="Arial, Helvetica, sans-serif" size="2">Table
Height (Less than 16) = </font></b>
<input type=text name=height value=<%=height%> size=2>
, </td>
</tr>
<tr>
<td><font face="Arial, Helvetica, sans-serif" size="2"><b>Select color
: -</b></font></td>
<td>
<select name="select">
<option value="#00FFFF" selected>Not specified</option>
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
<option value="Pink">Pink</option>
</select>
</td>
</tr>
<tr>
<td align=center colspan="2">
<input type=submit value="Click me Buddy !">
</td>
</tr>
</table>
</form>
<hr noshade>
<%
String w =request.getParameter("width");
String h= request.getParameter("height");
String col= request.getParameter("select");
if(w==null) w="15";
else w=request.getParameter("width");
if(h==null) h="15";
else h=request.getParameter("height");
if(col==null) col="#00FFFF";
else col=request.getParameter("select");
width = Integer.parseInt(w);
height = Integer.parseInt(h);
//if(width>15) width=15;
//if(width<0) width=0;
//if(height>15) height=15;
//if(height<0) height=0;
String[] colorArray={"00","11","22","33",
"44","55","66","77","88","99",
"AA","BB","CC","DD","EE","FF"};
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bordercolor="#CCCCCC" bgcolor=<%=col %>>
<tr>
<td align="center">
<table border=0 cellpadding =2 cellspacing=2>
<%
try {
%>
<%for (int y=0;y<=height;y++){%>
<tr>
<% for(int x=0;x<=width;x++) {
String bgColor="AA"+colorArray[y]+ colorArray[x];
%>
<td bgcolor=<%=bgColor%>> (<%=x%>,<%=y%> ) </td>
<%}%>
</tr>
<%}%>
<%
}
catch(Exception e)
{
out.print("<p align=justify><b>Please insert appropriate values. There is an Exception in your program which is :-"+e+"</b></p>");
}
%>
</table>
</td>
</tr>
</table>
<p>This is the following information which has been submitted to the server :-<br>
<b>This is width of the table :- <%=request.getParameter("width")%></b><br>
<b>This is heigth of the table :- <%=request.getParameter("height")%></b><br>
<b>This is bgcolor :- <%=request.getParameter("select")%></b><br>
</p>
<hr noshade>
</center>
</BODY>
</HTML>
Only you have to do is make an error page which will check the errors and handle it.
Here is my error.jsp
<%@ page isErrorPage="true" import="java.io.*" %>
<HTML>
<HEAD>
<TITLE>This is my error </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY bgcolor="beige">
<h1 align=center>We have an error message here <%=request.getRemoteHost();%></h1>
<table border=1>
<tr>
<td>Exception</td>
<td><b><%=exception%></b></td>
</tr>
<tr>
<td>Message</td>
<td><b><%=exception.getMessage()%></b></td>
</tr>
<tr>
<td>Localized Messege</td>
<td><%=exception.getLocalizedMessage()%></td>
</tr>
<tr>
<td>Stack Trace</td>
<td><pre>
<%
StringWriter sw =new StringWriter();
PrintWriter pw=new PrintWriter(sw);
exception.printStackTrace(pw);
out.println(sw);
%></pre>
</td>
</tr>
</table>
<center><a href="javascript:history.back(0)">Please Enter your values again</a></center>
</BODY>
</HTML>
I hope this helps you in solving your problem.
abhinav
Abhinav Sharma
Greenhorn

Joined: Aug 08, 2001
Posts: 25
Hi gabby,
One more thing why don't you keep yout table in for loop and check the condition there or may be use a while loop and put the td or tr inside the loop so that whenever it will pass from that loop it will either increase the trs or the tds.
abhinav
And sorry i have posted this same answer in your another question by mistake
Gabriel Fox
Ranch Hand

Joined: Oct 17, 2001
Posts: 170
Thanks Abhinav for your prompt response as usual.
At the moment my table is generated within a while-loop
by running thru the elements of a SortedMap.So,i need to maintain
the entries for each row whenever another item is removed from
the top list to add to the table(1 checkbox + item removed + textbox makes a row in the table).All i want is a scrollable table within a fixed box.
I will try to play around with your well laid out code and get back to U soonest.
Cheers.All ideas are welcomed please and codes.Have a nice day.
[This message has been edited by Gabriel Fox (edited December 05, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem displaying a dynamic table on a JSP....