Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Populating a List using JSTL and spring MVC

Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
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.
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
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.
A feeble attempt to tell you about our stuff that makes us money
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic