Jai le Leu

renommage et ajout logs

......@@ -4,7 +4,7 @@ import org.legrog.entities.Country;
import java.util.List;
public interface CountryService {
public interface ParameterService {
void addCountry(Country country);
......
......@@ -2,22 +2,27 @@ package org.legrog.application;
import org.legrog.entities.Country;
import org.legrog.entities.CountryRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
import javax.ejb.Stateless;
import javax.enterprise.inject.Alternative;
import javax.inject.Inject;
import java.util.List;
@Stateless
public class CountryServiceSpring implements CountryService {
public class ParameterServiceSpring implements ParameterService {
Logger logger = LoggerFactory.getLogger(getClass());
@Inject
CountryRepository repository;
public void addCountry(Country country) {
repository.save(country);
logger.debug("country added");
}
public List<Country> getAllCountries() {
......
package org.legrog.presentation;
import org.legrog.application.CountryService;
import org.legrog.application.ParameterService;
import org.legrog.entities.Country;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -11,8 +14,40 @@ import java.util.List;
@Named
@RequestScoped
public class CountryBean {
private Logger logger = LoggerFactory.getLogger(getClass());
@Inject
private CountryService service;
private ParameterService parameterService;
private List<Country> countries;
private String countryName;
public String add()
{
Country country = new Country();
country.setCountryName(countryName);
parameterService.addCountry(country);
logger.debug("add done");
return "success";
}
@PostConstruct
public void init() {
countries = parameterService.getAllCountries();
logger.debug("init done");
}
public ParameterService getParameterService() {
return parameterService;
}
public void setParameterService(ParameterService parameterService) {
this.parameterService = parameterService;
}
public List<Country> getCountries() {
return countries;
......@@ -22,10 +57,6 @@ public class CountryBean {
this.countries = countries;
}
private List<Country> countries;
private String countryName;
public String getCountryName() {
return countryName;
}
......@@ -33,16 +64,4 @@ public class CountryBean {
public void setCountryName(String countryName) {
this.countryName = countryName;
}
public String add()
{
Country country = new Country();
country.setCountryName(countryName);
service.addCountry(country);
return "success";
}
public void onload() {
countries = service.getAllCountries();
}
}
......
......@@ -6,9 +6,7 @@
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<body>
<f:metadata>
<f:event type="preRenderView" listener="#{countryBean.onload}" />
</f:metadata>
<ul>
<ui:repeat value="#{countryBean.countries}" var="country">
<li>#{country.countryName}</li>
......