Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Intro to Java Web Development with Spark Bells and Whistles Adding to and Iterating a List

Ernest Rodriguez
Ernest Rodriguez
17,643 Points

Can't seem to iterate through the list or get it to refresh. Maybe another set of eyes can catch my errors

 get("/ideas",(req, res) -> {
       Map<String, Object>model = new HashMap<>();
        model.put("ideas ",dao.findAll());
        return new ModelAndView(model,"ideas.mustache");
        },new HandlebarsTemplateEngine());

     post("/ideas",(req, res) -> {
         String title = req.queryParams("title");
         CourseIdea courseIdea = new CourseIdea(title,req.attribute("username"));
         return null;
{{#partial "content"}}

<h1>Current ideas</h1>
        {{#each ideas}}
            <form action="/ideas/{{slug}}/vote" method="post">
            {{title}} {{voteCount}} votes)  <button>Vote</button>
<form action="/ideas" method="post">
    <input type="text" name="title" placeholder="What is your idea"/>

Ernest Rodriguez
Ernest Rodriguez
17,643 Points

Correct. The template renders but the list doesn't show when I submit an item

Florian Tönjes
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

If the template renders and just the list items are missing it seems that the 'dao.findAll()' method is not returning anything.

Try debugging this: Set a breakpoint at the "model.put("ideas ",dao.findAll());" line and run the application in debug mode. When the breakpoint is hit type "dao.findAll()" into the "Evaluate Expression" prompt (Alt + F8 in IntelliJ) and see if it returns anything. If it doesn't you have to dig deeper until you find the root of the problem. It might be that you just haven't added any ideas to the SimpleCourseIdeaDAO, yet, that there is a problem in adding them, or that you made a mistake in the 'findAll()' method.

See if you can fix it yourself by debugging it first, should you not be successful come back and post your whole source code of the "Main.java", "SimpleCourseIdeaDAO.java" and "CourseIdea.java" files here.

Kind Regards, Florian Tönjes

3 Answers

I had the same problem. I figured out that I had an extra quotation mark (") in my ideas.hbs file

Hugo Hayes
Hugo Hayes
Courses Plus Student 13,146 Points

Hey, Ernest. Maybe you should check the add() and findAll() method in the SimpleCourseIdeaDAO.java. I was having the same problem just like you do. Then I realize that my add() method is still returning false.

Ivorine Do
Ivorine Do
5,014 Points

Hi Ernest,

Don't know if you solved the problem already, but I believe the list isn't showing the items because the model.put() method has an extra space in the first parameter "ideas ". Not sure if the extra space matters, but if "ideas " is being used as a reference, then the space would mess things up.