Jai le Leu

renommage et ajout logs

...@@ -4,7 +4,7 @@ import org.legrog.entities.Country; ...@@ -4,7 +4,7 @@ import org.legrog.entities.Country;
4 4
5 import java.util.List; 5 import java.util.List;
6 6
7 -public interface CountryService { 7 +public interface ParameterService {
8 8
9 void addCountry(Country country); 9 void addCountry(Country country);
10 10
......
...@@ -2,22 +2,27 @@ package org.legrog.application; ...@@ -2,22 +2,27 @@ package org.legrog.application;
2 2
3 import org.legrog.entities.Country; 3 import org.legrog.entities.Country;
4 import org.legrog.entities.CountryRepository; 4 import org.legrog.entities.CountryRepository;
5 +import org.slf4j.Logger;
6 +import org.slf4j.LoggerFactory;
5 //import org.slf4j.Logger; 7 //import org.slf4j.Logger;
6 //import org.slf4j.LoggerFactory; 8 //import org.slf4j.LoggerFactory;
7 9
8 import javax.ejb.Stateless; 10 import javax.ejb.Stateless;
9 -import javax.enterprise.inject.Alternative;
10 import javax.inject.Inject; 11 import javax.inject.Inject;
11 import java.util.List; 12 import java.util.List;
12 13
13 @Stateless 14 @Stateless
14 -public class CountryServiceSpring implements CountryService { 15 +public class ParameterServiceSpring implements ParameterService {
16 +
17 + Logger logger = LoggerFactory.getLogger(getClass());
15 18
16 @Inject 19 @Inject
17 CountryRepository repository; 20 CountryRepository repository;
18 21
19 public void addCountry(Country country) { 22 public void addCountry(Country country) {
23 +
20 repository.save(country); 24 repository.save(country);
25 + logger.debug("country added");
21 } 26 }
22 27
23 public List<Country> getAllCountries() { 28 public List<Country> getAllCountries() {
......
1 package org.legrog.presentation; 1 package org.legrog.presentation;
2 2
3 -import org.legrog.application.CountryService; 3 +import org.legrog.application.ParameterService;
4 import org.legrog.entities.Country; 4 import org.legrog.entities.Country;
5 +import org.slf4j.Logger;
6 +import org.slf4j.LoggerFactory;
5 7
8 +import javax.annotation.PostConstruct;
6 import javax.enterprise.context.RequestScoped; 9 import javax.enterprise.context.RequestScoped;
7 import javax.inject.Inject; 10 import javax.inject.Inject;
8 import javax.inject.Named; 11 import javax.inject.Named;
...@@ -11,8 +14,40 @@ import java.util.List; ...@@ -11,8 +14,40 @@ import java.util.List;
11 @Named 14 @Named
12 @RequestScoped 15 @RequestScoped
13 public class CountryBean { 16 public class CountryBean {
17 +
18 + private Logger logger = LoggerFactory.getLogger(getClass());
19 +
14 @Inject 20 @Inject
15 - private CountryService service; 21 + private ParameterService parameterService;
22 +
23 +
24 + private List<Country> countries;
25 + private String countryName;
26 +
27 + public String add()
28 + {
29 + Country country = new Country();
30 + country.setCountryName(countryName);
31 + parameterService.addCountry(country);
32 +
33 + logger.debug("add done");
34 + return "success";
35 + }
36 +
37 + @PostConstruct
38 + public void init() {
39 + countries = parameterService.getAllCountries();
40 + logger.debug("init done");
41 + }
42 +
43 +
44 + public ParameterService getParameterService() {
45 + return parameterService;
46 + }
47 +
48 + public void setParameterService(ParameterService parameterService) {
49 + this.parameterService = parameterService;
50 + }
16 51
17 public List<Country> getCountries() { 52 public List<Country> getCountries() {
18 return countries; 53 return countries;
...@@ -22,10 +57,6 @@ public class CountryBean { ...@@ -22,10 +57,6 @@ public class CountryBean {
22 this.countries = countries; 57 this.countries = countries;
23 } 58 }
24 59
25 - private List<Country> countries;
26 -
27 - private String countryName;
28 -
29 public String getCountryName() { 60 public String getCountryName() {
30 return countryName; 61 return countryName;
31 } 62 }
...@@ -33,16 +64,4 @@ public class CountryBean { ...@@ -33,16 +64,4 @@ public class CountryBean {
33 public void setCountryName(String countryName) { 64 public void setCountryName(String countryName) {
34 this.countryName = countryName; 65 this.countryName = countryName;
35 } 66 }
36 -
37 - public String add()
38 - {
39 - Country country = new Country();
40 - country.setCountryName(countryName);
41 - service.addCountry(country);
42 - return "success";
43 - }
44 -
45 - public void onload() {
46 - countries = service.getAllCountries();
47 - }
48 } 67 }
......
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
6 xmlns:ui="http://xmlns.jcp.org/jsf/facelets" 6 xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
7 xmlns:f="http://xmlns.jcp.org/jsf/core"> 7 xmlns:f="http://xmlns.jcp.org/jsf/core">
8 <body> 8 <body>
9 -<f:metadata> 9 +
10 - <f:event type="preRenderView" listener="#{countryBean.onload}" />
11 -</f:metadata>
12 <ul> 10 <ul>
13 <ui:repeat value="#{countryBean.countries}" var="country"> 11 <ui:repeat value="#{countryBean.countries}" var="country">
14 <li>#{country.countryName}</li> 12 <li>#{country.countryName}</li>
......