Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Populating a List using JSTL and spring MVC

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic