I'm working on a java-jsp project and I'm having a list of java objects to be displayed in the jsp page. The java line containing the list of those objects is as follows:
private List<String> derivedNames;
private List<DiffResponse> diffResponses;
private List<String> pRResults;
DiffResponse class is like this:
private String path;
private List<DiffOutput> diffOutputList;
private boolean isConflict;
In the jsp file when I console.log the diffOutput, it returns pure java object as stated below without showing the content inside.
org.example.rs.umt.DiffOutput@4d9d8911,
org.example.rs.umt.DiffOutput@3cc6fff7,
org.example.rs.umt.DiffOutput@311bce65,
org.example.rs.umt.DiffOutput@7611bf66,
org.example.rs.umt.DiffOutput@57e575b4,
org.example.rs.umt.DiffOutput@5c5711f8,
Below is the jsp code to retrieve the data:
<c:forEach items="${results.diffResponses}" var="diffResponse">
var distributionPath = '<c:out value="${diffResponse.distributionPath}"/>'
console.log("Dist: ",distributionPath);
var diffOutputList = '<c:out value="${diffResponse.diffOutputList}"/>'
console.log(diffOutputList);
</c:forEach>
Here the distributionPath is obtained as expected
CodePudding user response:
Well your diffOutputList
is in itself a list. So you have to do a nested <c:forEach>
like this:
<c:forEach items="${results.diffResponses}" var="diffResponse">
var distributionPath = '<c:out value="${diffResponse.distributionPath}"/>'
console.log("Dist: ",distributionPath);
<c:forEach items="${diffResponse.diffOutputList}" var="diffOutput">
var diffOutput = '<c:out value="${diffOutput.???}"/>'
console.log(diffOutput);
</c:forEach>
</c:forEach>
So if have included ??? in the code. There you have to set a field which exists in class DiffOutput.
Another way is to overwrite the .toString()
method in class DiffOutput.