Two Laptop Bag*
The moose likes HTML, CSS and JavaScript and the fly likes how to disaply list in ajax from spring controller(mvc) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to disaply list in ajax from spring controller(mvc)" Watch "how to disaply list in ajax from spring controller(mvc)" New topic
Author

how to disaply list in ajax from spring controller(mvc)

mallikarjun patil
Greenhorn

Joined: Jan 24, 2013
Posts: 1
I have developed an application using spring MVC. I am implemeting dashboard in it, which contains recently uploaded documents.
I want to display only 10 documents in a page and rest should come under pagination.
I am getting documents list through controller class, from there i'd like display the documents on a jsp page using Ajax.
But I am not getting how to display the documents(I am not getting response from ajax). Please find the below code and help me out.


in controller

@RequestMapping(value = "/fileList", method = RequestMethod.GET)
public @ResponseBody
List<File> fileList(HttpServletRequest req) {
Subject subject = SecurityUtils.getSubject();
Session session = subject.getSession();
User user1 = (User) session.getAttribute("objUser");
long userSesId = user1.getUserId();
int pageNumber=Integer.parseInt(req.getParameter("pageNo")) ;
List<File>files= dashboardService.listFiles(user1.getRoles().getRoleId(),pageNumber);
return files;

}

in jsp

<body>
<div class="dashboard">
<div class="dashboard_inner">
<div id="draggable1">
<div class="box">Recently Uploaded Documents</div>
<div class="slider">
<img src="../images/collapseminus.gif" />
</div>
<div class="internal">

<table cellpadding="0" cellspacing="2"
class="tablesorter">
<tr>
<th colspan="4"><h6>Recently Uploaded Documents</h6></th>
</tr>
<tr style="background: #dbebf8;">
<!-- <td width="20px"> </td> -->
<td width="50px" id="center"><span>Type</span></td>
<td width="250px" id="center"><span>Name</span></td>
<td width="150px" id="center"><span>Creation Date</span></td>
<td width="300px" id="center"><span>Author</span></td>

</tr>

<c:if test="${!empty lists}">
<c:forEach items="${lists}" var="FileList">
<tr>
<td><c:choose>
<c:when test="${FileList.contentType=='docx'}">
<img src="../images/word.jpg">
</c:when>
<c:when test="${FileList.contentType=='pdf'}">
<img src="../images/pdf.jpg">
</c:when>
<c:when test="${fn:toLowerCase(FileList.contentType)=='jpg'}">
<img src="../images/image.jpg">
</c:when>
<c:when test="${fn:toLowerCase(FileList.contentType)=='gif'}">
<img src="../images/image.jpg">
</c:when>
<c:when test="${fn:toLowerCase(FileList.contentType)=='png'}">
<img src="../images/image.jpg">
</c:when>
<c:when test="${fn:toLowerCase(FileList.contentType)=='bmp'}">
<img src="../images/image.jpg">
</c:when>
<c:when test="${FileList.contentType=='xlsx'}">
<img src="../images/xls.jpg">
</c:when>
<c:when test="${FileList.contentType=='xml'}">
<img src="../images/xml.jpg">
</c:when>
<ctherwise>
<img src="../images/others.png">
</ctherwise>
</c:choose></td>
<c:set var="string" value="${FileList.creationDate}" />
<c:set var="start" value=" " />
<c:set var="subCreationDate"
value="${fn:substringBefore(string,start)}" />
<td><a
href="../files/downloadDocumetInDocLib.html?path=<%=prop.getProperty("path")%>${FileList.filePath}&documentName=${FileList.fileName}">
<cut value="${FileList.fileName}"></cut> <sup
style="color: #ff0080;">New</sup>
</a></td>
<td id="center"><cut value="${subCreationDate}"></cut></td>
<td><cut value="${FileList.createdUser.userName}"></cut></td>
</tr>
</c:forEach>
</c:if>
<c:if test="${empty lists}">
<h4 class="displayMessagePosition">
<cut value="There are no files to display.."></cut>
</h4>
</c:if>
</table>
<c:if test="${!empty pageNosList}">
<c:forEach items="${pageNosList}" var="pageNo">

<INPUT TYPE=BUTTON onclick="updateContent('${pageNo}')">${pageNo}

</c:forEach>
</c:if>

</div>
</div>

in ajax

<script type="text/javascript">
var xmlHttp = null;
function updateContent(pageNo) {
alert("ajax");

try { // Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) { // Internet Explorer

try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {

try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}

xmlHttp.onreadystatechange = function() {

populateActivitiesPno(pageNo);

};

xmlHttp.open("GET",
"../dashboard/fileList.html?pageNo="
+ pageNo, true);
xmlHttp.send();

}

function populateActivitiesPno(pageNo) {
if (xmlHttp.readyState == 4) {
var lists = document.getElementById('draggable1');
alert(document.getElementById('draggable1'));
var response = xmlHttp.responseText;
if (response.length > 0) {
lists = response;
} else {
lists = '';
}
alert(document.getElementById('draggable1').value);
document.getElementById('draggable1').value = lists;

}
}
</script>


thanks in advance
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to disaply list in ajax from spring controller(mvc)