• Post Reply Bookmark Topic Watch Topic
  • New Topic

Showing an element of a list after a certain interval

 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am getting a list in the jsp page from a variable in the application scope.
The list obtained has some elements.
In my jsp page, i have a div in which i want to show the first element in the list,(which will be a String).
After a certain time(say 1 minute), i want to change it to the 2nd element , and soon, repeat over the list, showing elements repeatedly.

it seems we can use a javascript function for setTimeOut in the javascript, which gets called after every 1 minute, and i maintain a JS global variable, which tells me in which element of the list i am showing, and increase the variable accordingly,

but the problem is how can i access the list in the javascript.

or is there a better solution?

If someone can post a sample code demonstrating the code or direct me to a link, that would be great..

I will be grateful for any and all responses.

Thanks a lot,
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could write all the data into a JavaScript array or other construct. Or use Ajax to go back to the server for more information.

 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,

Bear Bibeault wrote:You could write all the data into a JavaScript array or other construct.

Can you please explain this with a small example.


 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JSP is just a template to create markup to send to the browser. You can use it to create an markup you want, including JavaScript statements.

So create a JavaScript array that contains your list data.
 
Rahul Babbar
Ranch Hand
Posts: 210
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i will try to make an ajax call (after each timeout ) that will just get the appropriate attribute from the servlet and return back the appropriate String...

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!