• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Next/Previous Button for arrayList

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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--;
}
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post the error message.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic