1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
package edu.sodteam.controller;
import edu.sodteam.bean.Advisor;
import edu.sodteam.form.SearchAdvisorForm;
import edu.sodteam.service.IServiceListAdvisors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.context.MessageSource;
import javax.validation.Valid;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@Controller
public class SearchAdvisorsController {
private static final Logger LOGGER = Logger.getLogger( SearchAdvisorsController.class.getName() );
@Autowired
private MessageSource messageSource;
@Autowired
IServiceListAdvisors service;
@GetMapping("/searchadvisor")
public String showSearchForm(ModelMap model) {
model.addAttribute("searchAdvisorForm", new SearchAdvisorForm());
// LOGGER.log(Level.INFO, "Displays the form to search the Advisors\n");
// if(model.get("searchAdvisorForm")==null){
// model.addAttribute("searchAdvisorForm", new SearchAdvisorForm());
// LOGGER.log(Level.INFO, "Displays the form to search the Advisors if it doesn't exist\n");
// }
return "advisor.search";
}
@PostMapping("/searchOneAdvisor")
public String showResultSearch(@Valid @ModelAttribute(value="searchAdvisorForm") SearchAdvisorForm advisorForm
,BindingResult pbinding, ModelMap model){
if(!pbinding.hasErrors()) {
String name = advisorForm.getName();
String surname = advisorForm.getSurname();
LOGGER.log(Level.INFO, "Displays the form to search the Advisors if it doesn't exist\n" + " nom : "+ advisorForm.getName());
List<Advisor> ListAdvisors = service.searchAdvisor(name,surname);
model.addAttribute("listAdvisors", ListAdvisors);
return "resultSearch";
}else {
model.addAttribute("searchAdvisorFrom", new SearchAdvisorForm());
model.addAttribute("message", messageSource.getMessage("controller.search.fail", new Object[] {}, null));
return "advisor.search";
}
}
} |