Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implementing a next button

Status
Not open for further replies.

johno77

Technical User
Nov 1, 2003
40
0
0
GB
Hi hopefully someone may be able to help me out on this one. I have created a servlet which access a DB, stores the results in an arraylist and passes this in the session object to a jsp page. At the moment the code below iterates throught the arraylist and prints out all the records. I would like to ammend this so that there is only one record at a time displayed and the user can use a next button to get the next element displayed from the arraylist. II have seen similar posts but am still struggling. if anyone could help it would be appreciated (code so far below)as i am having problens working out how to code the next button. Hope you can help.

thankyou

<%

for (int i=0;i<arrayList.size();i++)
{
Beaninfo info = (Beaninfo)arrayList.get(i);
String whatever=info.getSubmitter();
String whatever2=info.getUrl();
String whatever3=info.getSubmitt_date();
%>
<tr>
<td><%= whatever%></td>
<td><%= whatever1%></td>
<td><%= whatever2 %></td>
</tr>

<%

}

%>
 
I think the easiest way to do this would be using javascript and <div> tags (or maybe <span> tags if not using IE5 or above.

Take a look at this :
Code:
<html>
	<head>
		<script language=&quot;Javascript&quot;>
			showDivNum = eval(1);
			function showDiv() {
				document.getElementById(&quot;show&quot; +showDivNum).style.display = &quot;none&quot;;
				showDivNum++;
				document.getElementById(&quot;show&quot; +showDivNum).style.display = &quot;&quot;;
			}

		</script>
	</head>

	<body>

		<input type=&quot;button&quot; value=&quot;test&quot; onclick=&quot;showDiv()&quot;>
		<div id =&quot;show1&quot; style=&quot;display:&quot;> Hello 1 </div>
		<div id =&quot;show2&quot; style=&quot;display:none&quot;> Hello 2 </div>
		<div id =&quot;show3&quot; style=&quot;display:none&quot;> Hello 3 </div>
		<div id =&quot;show4&quot; style=&quot;display:none&quot;> Hello 4 </div>


	</body>

</html>
 
I think it's better to do paging on server side except if you're sure the user(s) will use only determined browsers.
So a session object for the paging would be useful, storing current page, lines per page...etc with methods to navigate thru them and request parameters to command it from buttons in your web GUI. ;)
 
But much slower ... anyway the <span> tag would achieve the same as the <div> tag, which is supported on netscape and clones. Plus, probably over 90% of people use IE anyway.

I find people these days are far too obsessed with doing things server side, when its much easier to do many user-interactive things client side.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top