• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populating a List using JSTL and spring MVC

 
Arshia Bora
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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}">

 
Arshia Bora
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic