File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes Populating a List using JSTL and spring MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Populating a List using JSTL and spring MVC " Watch "Populating a List using JSTL and spring MVC " New topic

Populating a List using JSTL and spring MVC

Arshia Bora

Joined: Jan 08, 2010
Posts: 7

I have a spring command object for my SimpleFormController. This object has few string items and few List items as attributes. I am using JSTL in my JSP page to populate the Lst box in view. I am using spring:bind tags to bind the command object attributes with view componenents. It works fine when we have all the attributes as String. But incase of List attributes, I do not see the spring binding happening correctly. This results the incorrect rendering of view with no items in the list.

I can see that the List is getting populated properly on Server side. But view is not able to display the same. Looks like the JSP code written by me is incorrect. Can someone provide hint or sample code for this scenario?

My sample JSP code is:

Dispatcher Servlet Content:

Controller class code:

When I print currentCity.cityId in JSP, it shows up blank. So looks like there is problem of binding the List item userBean.location. This is what I feel? Any other clues would be appreciated.
David Newton

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Arshia Bora wrote:

I guess there's typo error with locations (supposed to be location).

<spring:bind path="userBean.location">

<c:forEach var="currentCity" items="${locations}">
should be corrected to
<c:forEach var="currentCity" items="${location}">

SCJP 1.5, SCEA, ICED (287,484,486)
Arshia Bora

Joined: Jan 08, 2010
Posts: 7
I tried this but it does not work. I tried multiple things such as overriding referenceData and updating the location list. I also tried filling this list in formBackingObject method. But nothing shows up in JSP. I would appreciate any help on this as I am struggling with this problem for last 4-5 days.
I agree. Here's the link:
subject: Populating a List using JSTL and spring MVC
It's not a secret anymore!