Jean-Francois Leveque

Liste qui ne marche pas

...@@ -2,8 +2,11 @@ package org.legrog.application; ...@@ -2,8 +2,11 @@ package org.legrog.application;
2 2
3 import org.legrog.entities.Country; 3 import org.legrog.entities.Country;
4 4
5 +import java.util.List;
6 +
5 public interface CountryService { 7 public interface CountryService {
6 8
7 void addCountry(Country country); 9 void addCountry(Country country);
8 10
11 + public List<Country> getAllCountries();
9 } 12 }
......
...@@ -8,7 +8,7 @@ import org.legrog.entities.CountryRepository; ...@@ -8,7 +8,7 @@ import org.legrog.entities.CountryRepository;
8 import javax.ejb.Stateless; 8 import javax.ejb.Stateless;
9 import javax.enterprise.inject.Alternative; 9 import javax.enterprise.inject.Alternative;
10 import javax.inject.Inject; 10 import javax.inject.Inject;
11 -//import java.util.List; 11 +import java.util.List;
12 12
13 @Stateless 13 @Stateless
14 public class CountryServiceSpring implements CountryService { 14 public class CountryServiceSpring implements CountryService {
...@@ -20,4 +20,7 @@ public class CountryServiceSpring implements CountryService { ...@@ -20,4 +20,7 @@ public class CountryServiceSpring implements CountryService {
20 repository.save(country); 20 repository.save(country);
21 } 21 }
22 22
23 + public List<Country> getAllCountries() {
24 + return repository.findAll();
25 + }
23 } 26 }
......
...@@ -14,7 +14,18 @@ public class CountryBean { ...@@ -14,7 +14,18 @@ public class CountryBean {
14 @Inject 14 @Inject
15 private CountryService service; 15 private CountryService service;
16 16
17 + public List<Country> getCountries() {
18 + return countries;
19 + }
20 +
21 + public void setCountries(List<Country> countries) {
22 + this.countries = countries;
23 + }
24 +
25 + private List<Country> countries;
26 +
17 private String countryName; 27 private String countryName;
28 +
18 public String getCountryName() { 29 public String getCountryName() {
19 return countryName; 30 return countryName;
20 } 31 }
...@@ -30,4 +41,8 @@ public class CountryBean { ...@@ -30,4 +41,8 @@ public class CountryBean {
30 service.addCountry(country); 41 service.addCountry(country);
31 return "success"; 42 return "success";
32 } 43 }
44 +
45 + public void onload() {
46 + countries = service.getAllCountries();
47 + }
33 } 48 }
......
...@@ -23,13 +23,11 @@ ...@@ -23,13 +23,11 @@
23 <h:outputText value="Add country"/> 23 <h:outputText value="Add country"/>
24 </h:commandLink> 24 </h:commandLink>
25 </li> 25 </li>
26 - <!--
27 <li> 26 <li>
28 <h:commandLink action="listCountries"> 27 <h:commandLink action="listCountries">
29 <h:outputText value="List countries"/> 28 <h:outputText value="List countries"/>
30 </h:commandLink> 29 </h:commandLink>
31 </li> 30 </li>
32 - -->
33 </ul> 31 </ul>
34 </h:form> 32 </h:form>
35 </body> 33 </body>
......
...@@ -6,6 +6,15 @@ ...@@ -6,6 +6,15 @@
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>
10 + <f:event type="preRenderView" listener="#{countryBean.onload}" />
11 +</f:metadata>
12 +<ul>
13 + <ui:repeat value="#{countryBean.countries}" var="country">
14 + <li>#{country.countryName}</li>
15 + </ui:repeat>
16 +</ul>
17 +
9 <h:outputLabel value="Hello, world"/> 18 <h:outputLabel value="Hello, world"/>
10 </body> 19 </body>
11 </html> 20 </html>
......