PageRenderTime 23ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/jcg-andygene-web-archetype/src/main/resources/archetype-resources/src/main/java/web/ReportsController.java

http://jcg-andygene-web.googlecode.com/
Java | 88 lines | 70 code | 18 blank | 0 comment | 1 complexity | 1863a710f84ff65f2b6f155347bd9ae8 MD5 | raw file
 1#set( $symbol_pound = '#' )
 2#set( $symbol_dollar = '$' )
 3#set( $symbol_escape = '\' )
 4package ${package}.web;
 5
 6
 7import javax.servlet.http.HttpServletRequest;
 8import javax.validation.Valid;
 9
10import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
11
12import org.springframework.beans.factory.annotation.Autowired;
13import org.springframework.stereotype.Controller;
14import org.springframework.ui.Model;
15import org.springframework.ui.ModelMap;
16import org.springframework.validation.BindingResult;
17import org.springframework.web.bind.annotation.ModelAttribute;
18import org.springframework.web.bind.annotation.RequestMapping;
19import org.springframework.web.bind.annotation.RequestMethod;
20
21import ${package}.service.ReportsService;
22import ${package}.util.FormatUtil;
23import ${package}.util.ReportUtil;
24
25@RequestMapping("/reports")
26@Controller
27public class ReportsController {
28	
29	
30	
31	@Autowired
32	private ReportsService reportsService;
33	
34	
35	
36	@RequestMapping(method = RequestMethod.GET)
37	public String fireReport(@ModelAttribute("formatUtil") @Valid FormatUtil formatUtil,BindingResult result,ModelMap modelMap,Model model,HttpServletRequest request) {
38		JRBeanCollectionDataSource jrDataSource = new JRBeanCollectionDataSource(reportsService.getReports(),false);
39		modelMap.put("format",formatUtil.getFormat());
40		modelMap.put("reportList", jrDataSource);
41		return "reportList";
42	 }
43	
44	@RequestMapping(method = RequestMethod.POST)
45    public String createForm(@ModelAttribute("reportUtil") @Valid ReportUtil reportUtil,BindingResult result,Model model,HttpServletRequest request) {
46		if (result.hasErrors()) { 
47			model.addAttribute("entitiesSelected","false");
48	        model.addAttribute("jmsSelected","false");
49	        model.addAttribute("reportsSelected","true");
50	        model.addAttribute("droolsSelected","false");
51	        model.addAttribute("activitiSelected","false");
52			return "reports/init";  
53		}  
54		reportsService.initReports(reportUtil.getNumber().intValue());
55		model.addAttribute("formatUtil", new FormatUtil());
56		model.addAttribute("entitiesSelected","false");
57        model.addAttribute("jmsSelected","false");
58        model.addAttribute("reportsSelected","true");
59        model.addAttribute("droolsSelected","false");
60        model.addAttribute("activitiSelected","false");
61		return "reports/generate";
62    }
63	
64	@RequestMapping(params = "form", method = RequestMethod.GET)
65    public String createForm(Model model) {
66    
67        model.addAttribute("reportUtil", new ReportUtil());
68        model.addAttribute("entitiesSelected","false");
69        model.addAttribute("jmsSelected","false");
70        model.addAttribute("reportsSelected","true");
71        model.addAttribute("droolsSelected","false");
72        model.addAttribute("activitiSelected","false");
73        return "reports/init";
74    }
75	
76	@RequestMapping(params = "generate", method = RequestMethod.GET)
77    public String generateForm(Model model) {
78    
79        model.addAttribute("formatUtil", new FormatUtil());
80        model.addAttribute("entitiesSelected","false");
81        model.addAttribute("jmsSelected","false");
82        model.addAttribute("reportsSelected","true");
83        model.addAttribute("droolsSelected","false");
84        model.addAttribute("activitiSelected","false");
85        return "reports/generate";
86    }
87
88}