Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Next/Previous Button for arrayList  RSS feed

 
m brymer
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to java and am trying to create a jsp page with prev/next buttons that show each individual record in an arrayList. My previous button works like it should be the next button but I get errors if I try to reverse the syntax. I really need help! My code is below. Thanks all!


int agreementIndex = 0;
int nextIndex = 0;
int previousIndex = 0;

agreements = (ArrayList)session.getAttribute("agreements");
if (agreements == null) {

}

request.setAttribute("agreements", agreements);

if (request.getParameter("agreementIndex") != null) {
agreementIndex = Integer.parseInt(request.getParameter("agreementIndex"));

}

Agreement agreement = (Agreement)agreements.get(agreementIndex);

if ((agreementIndex+1) >= agreements.size()) {
nextIndex = -1;
} else {
nextIndex = agreementIndex++;
}

if ((agreementIndex-1) < 0) {
previousIndex = -1;
} else {
previousIndex = agreementIndex--;
}
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!