Jean-Francois Leveque

Liste qui ne marche pas

......@@ -2,8 +2,11 @@ package org.legrog.application;
import org.legrog.entities.Country;
import java.util.List;
public interface CountryService {
void addCountry(Country country);
public List<Country> getAllCountries();
}
......
......@@ -8,7 +8,7 @@ import org.legrog.entities.CountryRepository;
import javax.ejb.Stateless;
import javax.enterprise.inject.Alternative;
import javax.inject.Inject;
//import java.util.List;
import java.util.List;
@Stateless
public class CountryServiceSpring implements CountryService {
......@@ -20,4 +20,7 @@ public class CountryServiceSpring implements CountryService {
repository.save(country);
}
public List<Country> getAllCountries() {
return repository.findAll();
}
}
......
......@@ -14,7 +14,18 @@ public class CountryBean {
@Inject
private CountryService service;
public List<Country> getCountries() {
return countries;
}
public void setCountries(List<Country> countries) {
this.countries = countries;
}
private List<Country> countries;
private String countryName;
public String getCountryName() {
return countryName;
}
......@@ -30,4 +41,8 @@ public class CountryBean {
service.addCountry(country);
return "success";
}
public void onload() {
countries = service.getAllCountries();
}
}
......
......@@ -23,13 +23,11 @@
<h:outputText value="Add country"/>
</h:commandLink>
</li>
<!--
<li>
<h:commandLink action="listCountries">
<h:outputText value="List countries"/>
</h:commandLink>
</li>
-->
</ul>
</h:form>
</body>
......
......@@ -6,6 +6,15 @@
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>
</ui:repeat>
</ul>
<h:outputLabel value="Hello, world"/>
</body>
</html>
......