Reputation: 1443
Making a system with my group in school and got a problem figuring out how to do this...
I have a table, I got JSP to fill out with some data using a for-loop.
Each of the data in the table-cells represent an object using the power of JPA. They, of course, have an id
of their own.
In our java code, we want to be able to finish off a Task using a method we called setDone(true)
.
How are can this be done visually on the JSP page? I was guessing Jquery/ajax was a way to do it.
I hope this makes sense. Here you can see the tick/untick buttons.
EDIT:
This is how my HTML/JSP code looks like:
"> "> "> ">And this is the jquery:
$(function() {
$('#done').click(function() {
$.post("servletUri", {id: idParam, done: doneParam}, function() {
$("doneImage-id").attr("src", correction-done.png);
});
});
});
But i'm still a rookie to jquery, so I have no idea how to implement this.
Upvotes: 0
Views: 877
Reputation: 54790
You can make the call using jQuery but you'll need something to "answer" that call and actually update the database using JPA. Usually you'll use some type of MVC framework like Spring MVC or Struts, but you can use a plain servlet as well.
To summarize:
setDone
and update.Upvotes: 1
Reputation: 597116
Yes, jquery is a good option. Here are a few basic steps:
<img id="doneImage-${row.id}" onclick="setDone('${row.id}', ${!row.done})" />
in the foreach loop.the javascript function setDone
should invoke a servlet via ajax
$.post("servletUri", {id: idParam, done: doneParam}, function() {
$("doneImage-id").attr("src", ...); // set here the new image
};
This will result in each row invoking the setDone function with a different id parameter, so that it knows what row you've clicked.
Upvotes: 1