Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding a new lement to an ArrayList in JavaScript  RSS feed

 
aydeniz kirmizi
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

my request is related to Java/Java Script, so I decided to post it in JSP forum.

what I want to do is:

I have a form which contains a list of customers. the user can multi select from this list and do a bulk processes, such as delete, approve etc..

so as the user clicks on the checkbox, I re-read the checked rows and create an array List "batchIds" . Eventually I want to set the "BatchIdsToProcess" (setBatchIdsToProcess) with this array list.

the issue is , this line will be printed in the javascript method and will not be recognise as a java script command.

my question is, how can I add an element to a Java defined ArrayList within a JavaScript method.




return true;
}
[/code]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:

First, you can't. JavaScript runs on the client long after the JSP runs. Please read this article to learn what JSP is.

Second, Java code in a JSP as a bad practice that's been discredited for over 10 years. Don't you think it's time to stop writing JSPs as if it were still 2001?
 
aydeniz kirmizi
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

thanks for the quick reply and also sharing the link. I will ready the article, I am sure I will find very useful information.

Unfortunately I am dealing with some legacy code, and cannot change them unless I am asked. This is why I am stacked.

Do you recommend any other solution?

thanks a lot!
 
S Subbu
Ranch Hand
Posts: 87
jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi aydeniz ,

Why dont you choose Ajax Call when you checked a checkbox.

Ajax Calls are so easy and do what you need (i think).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65825
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except that the Ajax request will have no access to the ArrayList created in the JSP which has executed before the page is even sent to the browser.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!