JQuery AJAX calls within portlet jsp pages
abdulbasitmughal Sep 30, 2013 10:23 AMI have tried to add JQuery AJAX calls in jsp page within portlet in the following way ..
1- Added code into JSP page
<script type="text/javascript">
jQuery(document).ready(function(){
$.ajax({
type: "POST", // HTTP method POST or GET
url: '<portlet:actionURL name="getAlertList"/>', //Where to make Ajax calls
//dataType:"text", // Data type, HTML, json etc.
dataType: 'html',
success: function(data) {
$('#manage_user table > tbody:first').append(data);
//alert(data);
},
error: function(xhr, ajaxOptions, thrownError) {
//On error, we alert user
alert(thrownError);
},
complete: function() {
//alert('update success');
}
});
});
</script>
2- Added code into portlet controller
@ProcessAction(name="getAlertList")
public void getAlertList(ResourceRequest request, ResourceResponse response) throws PortletException, IOException {
PrintWriter writer = response.getWriter();
int id = Integer.parseInt(request.getParameter("id"));
IRecordsJdbcDAO recordsDAO = new RecordsJdbcDAO();
List<AlertsForm> alertList = recordsDAO.getAlerts(id);
for (AlertsForm alert: alertList) {
writer.write("<tr>");
writer.write("<tb>"+alert.getLabel()+"</tb>");
writer.write("<tb>"+alert.getOccurrenceDate()+"</tb>");
writer.write("<tb>"+alert.getClosingDate()+"</tb>");
writer.write("</tr>");
}
writer.flush();
writer.close();
}
3- In response complete HTML of first home page displayed ..
Can anyone help what is the correct way to do that? If it is correct way then what i am doing wrong.. I have also tried
@Override
public void serveResource(ResourceRequest request, ResourceResponse response) throws IOException, PortletException {
but no resolution..
Thanks,