Skip to content

Instantly share code, notes, and snippets.

@DeepSky8
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save DeepSky8/4e11e6b7e726818e44db to your computer and use it in GitHub Desktop.

Select an option

Save DeepSky8/4e11e6b7e726818e44db to your computer and use it in GitHub Desktop.
Code compiles. Search executes, and the loggers indicate that when no checkbox is marked for categoriesA and difficultiesB, the correct values are supplied. The logger on line 79 also indicates the Issue(s) that are being found by the search on line 77. The browser displays issueList.html, but it doesn't show any of the Issues that the logger on…
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<String> categoriesA = searchTerms.getCategories();
logger.info(categoriesA);
if (categoriesA == null){
categoriesA = new ArrayList<String>();
categoriesA.add("Feature");
categoriesA.add("Problem");
categoriesA.add("Enhancement");
}
List<Integer> difficultiesB = searchTerms.getDifficulties();
logger.info(difficultiesB);
if(difficultiesB == null) {
difficultiesB = new ArrayList<Integer>();
difficultiesB.add(1);
difficultiesB.add(5);
difficultiesB.add(9);
difficultiesB.add(15);
difficultiesB.add(20);
difficultiesB.add(27);
difficultiesB.add(35);
}
logger.info(categoriesA);
logger.info(difficultiesB);
List<Issue> searchResults = issueRepository.findByTitleLikeAndDescriptionLikeAndCategoryInAndDifficultyIn("%" + searchTerms.getTitle() + "%","%" + searchTerms.getDescription() + "%", categoriesA, difficultiesB);
model.addAttribute("issues", searchResults);
logger.info(searchResults);
return "issueList";
}
}
<!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