• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help getting c:foreach jsp iterate over list working  RSS feed

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be simple, but i cant get the following code to work thanks for anyhelp



here is my controller code both lists are being passed in



I cant see anything wrong with my JSP

all it outputs is

Funds:

list

which looks like outputs the text but both lists are empty.
 
Vivek SharmaJi
Ranch Hand
Posts: 38
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please try like this in your cotroller and see if this works...

@RequestMapping(method = RequestMethod.GET)
public ModelMap printWelcome(ModelMap model) {
......
......
return model;
}
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vivek SharmaJi didnt work, returning the modal or return the name of the JSP page did not make a difference it can resolve strings an objects, seems to be having problems with the collections.

But thanks for your input.
 
Vivek SharmaJi
Ranch Hand
Posts: 38
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, to me also code looks fine. I was thinking if somehow 'model' is being lost.

Also, can you please try using following as well on jsp page and see the result.

<cut value="${fund.fundName}"/>
 
Vivek SharmaJi
Ranch Hand
Posts: 38
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, to me also code looks fine. I was thinking if somehow 'model' is being lost.

Also, can you please try using following as well on jsp page and see the result.

<c : out value="${fund.fundName}"/>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having trouble reading your code with all the wonky indentation. But I do not see how your JSP could possible be printing out those labels when they do not exist in the HTML. Are you posting the real code? Or just paraphrasing it?

What is the HTML that is rendered to the browser? (View Source)
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Message : Spring 3 MVC Hello Tony
Fund Holder Id Fund Holder Name
10720031 Barlings
Fund Id Fund Name
Funds:
lists :



It looks like the collections are there its just not interating over them

Thanks
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Changed the JSP a little

these are the two foreach loops

 
Vivek SharmaJi
Ranch Hand
Posts: 38
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seeing html it seems tld is not being resolved it should not print as follows, it should be resolved.
<c:forEach var="fund" items="

Hence please check following import and your application is able to find jstl tag lib.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vivek SharmaJi

Its now working I forgot to add <%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core”%> Thats what cpmes of not doing front end for years.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!