• Post Reply Bookmark Topic Watch Topic
  • New Topic

best practice for updating data displayed on html page

 
Edmund Castermund
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Let's say I have class:


and I have a dogPoundDetail.jsp file that renders the dog pound info, and info about each dog.

I want an edit button at the dog pound level and at each dog level.

Assuming I'm updating the dog pound info, what is the best practice for this?

  • link to servlet -> build dog pound obj -> jsp form -> dog pound update servlet -> redirect to updated dog pound detail
  • edit button launches javascript function that alters relevent div to form -> form renders -> servlet to update dog pound data -> redirect to updated dog pound detail
  • edit button launches function that builds popup form with jquery-ui -> form is populated and sent to servlet via ajax -> ??? how to display new data on page this way?


  • I'm a noob with ajax, thanks!


    I also notice that based on these params:


    this forum uses the first option?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65522
    105
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Refreshing the entire page is a very old-fashioned and obsolete way to proceed. Using Ajax and JavaScript to only update the information would be the more modern way to approach the task. Most modern would be an SPA using a JavaScript MVC framework such as AngularJS.
     
    Edmund Castermund
    Ranch Hand
    Posts: 102
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    so I got that part working. Essentially, when I create the page, I have an html form that is set not to display. Then when a user hits the edit button, the existing html fades out, the form fades in, and the update is done with ajax. Then I fade in the return value from the servlet.

    Is it a best practice to create a hidden form in that way, or should the jquery build the html form? Can that be done from a template?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65522
    105
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Either approach is fine. Use whichever works best for you.
     
    Edmund Castermund
    Ranch Hand
    Posts: 102
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    thanks for replies...
    googling around and I think mustache.js is a good option
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65522
    105
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you are going to use a standalone templating engine, I like handlebars (based on mustache) better as it is more feature rich.
     
    J. Kevin Robbins
    Bartender
    Posts: 1801
    28
    Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I just looked at that Handlebars page. Interesting, but I can't quite get my head wrapped around it. What are templates for?

    Can you Explain-Like-I'm-5 what Handlebars does for you?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65522
    105
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It allows you to use a template to create HTML fragments to insert into the DOM (as opposed to building the elements yourself and putting them together). You can almost think of it as a mini-client-side version of JSP.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!