package com aci payments controller import com aci payments controller

 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
64
65
66
67
package com.aci.payments.controller;
import com.aci.payments.controller.form.BillerForm;
import com.aci.payments.model.Biller;
import com.aci.payments.service.BillerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeoutException;
@Controller
@RequestMapping("/biller")
public class BillerController {
private final static String BILLER_PAGE = "biller";
private final static String BILLERS_PAGE = "redirect:/billers";
@Autowired
private BillerService billerService;
@RequestMapping(method = RequestMethod.GET)
public String showBiller(ModelMap modelMap,
HttpServletRequest request,
HttpServletResponse response) {
Biller biller=null;
if(request.getParameter("id")!=null) {
biller = billerService.getBiller(Long.valueOf(request.getParameter("id")));
}
else if(request.getSession().getAttribute("biller")!=null){
biller = (Biller)request.getSession().getAttribute("biller");
}
// System.out.print(biller.getCompany());
request.getSession().setAttribute("biller", biller);
modelMap.addAttribute("biller", biller);
return BILLER_PAGE;
}
@RequestMapping(method = RequestMethod.POST , params = "delete")
public String deleteBiller(HttpServletRequest request, HttpServletResponse response) throws IOException {
Biller biller = (Biller) request.getSession().getAttribute("biller");
System.out.println("biller" + biller.getCompany());
billerService.deleteBiller(biller);
System.out.println("deleted");
return BILLERS_PAGE;
}
@RequestMapping(method = RequestMethod.POST, params = "update")
public String updateBiller(@ModelAttribute BillerForm form, HttpServletRequest request, HttpServletResponse response) throws IOException {
Biller biller = (Biller) request.getSession().getAttribute("biller");
System.out.println("form"+form.getCompany());
if (!form.isEmptyForm()) {
biller.setCompany(form.getCompany());
billerService.updateBiller(biller);
request.getSession().setAttribute("biller", biller);
}
return BILLER_PAGE;
}
}