• Post Reply Bookmark Topic Watch Topic
  • New Topic

When should I use JavaScript for data append and when not?

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

I have a question that suppose I am making a web application that is a shoping website and there are a lot of different model products that are set by my controller and I am consuming them in my view

My Question is my approach is this

1)A Block suppose their is productsList and productBlock I am first Iterating through by Model Item and then setting all values on the productBlock using JQuery something like

myBlock.find("myId").text("myText")...
..
..

and finally
productsList.append("someBlock");

and I am doing for each model that is present in the request data

My Question is If I want something like dynamically appending some div to an existing div can I do that without using JavaScript like e.append() function?

Can I do that only using JSP?

Thanks
 
Tapas Chand
Ranch Hand
Posts: 602
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
div is client side element.
jsp is server side code.
jsp cannot manipulate a div at client side.
It has to be done with JavaScript.
Otherwise you can go to server side with the help of ajax and manipulate the div in ajax response, again this has to be done with JavaScript.
Whether you want to do at client side or using ajax, depends on your design and requirement.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back in the old days, one submitted the whole page and rewrote the whole thing with any change, no matter how minute, using JSP. You can still do it that way, but it's the equivalent of using bloodletting to cure disease. (In other words, hopelessly antiquated.)

Using JavaScript to make changes to the page without needing a full refresh is the modern way to accomplish things.

Think of things this way: JSP is used for the initial page load, JavaScript for everything after that. (That's simplistic, but a basic rule of thumb.)

Please read this article if you need a refresh on how JSP works.
 
Tapas Chand
Ranch Hand
Posts: 602
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question.
Why OP wants to do it using only JSP.
Is there any specific reason to avoid JavaScript?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!