Created
April 10, 2015 17:00
-
-
Save DeepSky8/656fb454bb197d0c01f1 to your computer and use it in GitHub Desktop.
Trying to get issueList.html to display search results, not just the database list of issues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kyrlach.issuetracker.issue; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import org.apache.log4j.LogManager; | |
| import org.apache.log4j.Logger; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.stereotype.Controller; | |
| import org.springframework.ui.Model; | |
| import org.springframework.web.bind.annotation.ModelAttribute; | |
| import org.springframework.web.bind.annotation.RequestMapping; | |
| import org.springframework.web.bind.annotation.RequestMethod; | |
| import com.kyrlach.issuetracker.login.LoginController; | |
| import com.kyrlach.issuetracker.login.LoginForm; | |
| import com.kyrlach.issuetracker.login.User; | |
| @Controller | |
| @RequestMapping("/issues") | |
| public class IssueController { | |
| private static Logger logger = LogManager.getLogger(IssueController.class); | |
| @Autowired | |
| private IssueRepository issueRepository; | |
| @RequestMapping(method = RequestMethod.GET) | |
| public String issues(Model model) { | |
| model.addAttribute("issues", issueRepository.findAll()); | |
| return "issueList"; | |
| } | |
| @RequestMapping(value = "/new", method = RequestMethod.GET) | |
| public String newIssue(Model model) { | |
| model.addAttribute("issueForm", new IssueForm()); | |
| return "newIssue"; | |
| } | |
| @RequestMapping(value = "/new", method = RequestMethod.POST) | |
| public String saveIssue(@ModelAttribute IssueForm issueForm, Model model) { | |
| Issue newIssue = new Issue(issueForm.getTitle(), issueForm.getDescription(), issueForm.getCategory(), issueForm.getDifficulty()); | |
| issueRepository.save(newIssue); | |
| return "redirect:/issues"; | |
| } | |
| @RequestMapping(value = "/search", method = RequestMethod.GET) | |
| public String newSearch(Model model) { | |
| model.addAttribute("searchTerms", new IssueSearchForm()); | |
| return "issueSearch"; | |
| } | |
| @RequestMapping(value = "/search", method = RequestMethod.POST) | |
| public String submittedData(@ModelAttribute IssueSearchForm searchTerms, Model model) { | |
| logger.info(searchTerms); | |
| List<Issue> searchResults = issueRepository.findByTitleLikeAndDifficultyIn(searchTerms.getTitle(), searchTerms.getDifficulties()); | |
| logger.info(searchResults); | |
| model.addAttribute("issues", searchResults); | |
| return "issueList"; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <html xmlns:th="http://www.thymeleaf.org"> | |
| <head> | |
| <title>Issue Tracker -- Issues</title> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
| <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css" /> | |
| </head> | |
| <body> | |
| <a href="/issues/new">New Issue</a> | |
| <a href="/issues/search">New Search</a> | |
| <table class="pure-table pure-table-striped"> | |
| <thead> | |
| <tr> | |
| <th>Title</th> | |
| <th>Name</th> | |
| <th>Category</th> | |
| <th>Difficulty</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr th:each="issue : ${issues}"> | |
| <td th:text="${issue.title}">My First Issue</td> | |
| <td th:text="${issue.description}">This is _very_ important</td> | |
| <td th:text="${issue.category}">Type of problem</td> | |
| <td th:text="${issue.difficulty}">How hard is this?</td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment