What I'm looking for is that when I click on the button the comment table is updated asynchronously, that is, I'm loaded with a jquery function that updates a table in the JSP. I leave the code, because currently I miss the "alert" error:
Controller:
@RequestMapping(value="/updatecomments")
public @ResponseBody
String update(@RequestParam int lolMatchId){
Collection<CommentMatch> cm= commentMatchService.findAllByLolMatchId(lolMatchId);
List<CommentMatch> cmatch = new ArrayList<CommentMatch>(cm);
Collections.reverse(cmatch);
Gson gson = new Gson();
return gson.toJson(cmatch);
}
Jsp:
<form method="post">
<input type="button" value="Refresh" id = "b" onclick="searchAjax()" />
</form>
<display:table name="commentsMatch" id="c" requestURI="lolMatch/match.do" pagesize="5" class="displaytag" >
<display:column property="customer.name" />
<display:column property="description" />
</display:table>
<script type="text/javascript" src='js/jquery.min.js'></script>
<script type='text/javascript'>
function searchAjax() {
$.ajax({
dataType : "json",
url : "/${pageContext.request.contextPath}/updatecomments",
headers : {
'Accept' : 'application/json',
'Content-Type' : 'application/json'
},
type: 'POST',
success : function(response) {
$.each( response,function(key, comment) {
var htmlrow ="<tr><td>" + comment.description + "</td></tr>";
$('#c').append(htmlrow);
});
},
error : function(){
alert("error");
}
});
}
</script>