Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialErnest Rodriguez
17,643 PointsCan'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"));
dao.add(courseIdea);
res.redirect("/ideas");
return null;
});
{{#partial "content"}}
<h1>Current ideas</h1>
<ul>
{{#each ideas}}
<li>
<form action="/ideas/{{slug}}/vote" method="post">
{{title}} {{voteCount}} votes) <button>Vote</button>
</form>
</li>
{{/each}}
</ul>
<form action="/ideas" method="post">
<input type="text" name="title" placeholder="What is your idea"/>
<button>Submit</button>
</form>
{{/partial}}
{{>base.mustache}}
Ernest Rodriguez
17,643 PointsCorrect. The template renders but the list doesn't show when I submit an item
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 PointsIf 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
Chitra Sharathchandra
6,188 PointsI had the same problem. I figured out that I had an extra quotation mark (") in my ideas.hbs file
Hugo Hayes
Courses Plus Student 13,146 PointsHey, 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
5,014 PointsHi 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.
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 PointsFlorian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 PointsThis looks ok. What's the result you are getting? Is the template rendering and just missing the list items?
Regards, Florian