Sumit D
Sumit D

Reputation: 411

Spring:Display List<ObjectID> in jsp view

I am new bie to spring. My domain is

@Document
public class Post {

     @Id
     private ObjectId _id;
     private String postTitle;
     private String postDesc;
     private ObjectId owner=Global.getCurruser();
     private List<ObjectId> intrestReceived=new ArrayList<ObjectId>();

// Getters and setters
}

my controller looks like

    @RequestMapping(value = "/post/intrestReceived", method = RequestMethod.GET)
    public String intrestReceived(Model model){
        List<Post> result=postService.intrestReceived();
        model.addAttribute("result", result);
        return "intrestReceived";
    }

and my view looks like :

<form:form id="idForm" class="form-horizontal" method="GET">
        <table border=1>
            <tr>
                <td><b>Post ID</b></td>
                <td><b>Post Desc</b></td>
                <td><b>Intrest Received</b></td>
            </tr>
            <c:forEach items="${result}" var="result">
                <tr>
                    <td>${result.getId()}</td>
                    <td>${result.postDesc}</td>
                    <td>${result.getIntrestReceived()}</td>
                </tr>
            </c:forEach>
        </table>
    </form:form>

Here <td>${result.getIntrestReceived()}</td> returns the List<ObjectId> how can I iterate it to get individual id in seperate row. Sorry for my english.

Upvotes: 0

Views: 439

Answers (1)

Renjith
Renjith

Reputation: 3274

Try this:

<c:forEach items="${result}" var="item">
                <tr>
                    <td>${item._id}</td>
                    <td>${item.postDesc}</td>
                  <c:forEach items="${result.intrestReceived}" var="intr">
                    <tr><td>${intr._id}</td></tr>
          </c:forEach>
                </tr>
</c:forEach>

Upvotes: 1

Related Questions