Showing
8 changed files
with
128 additions
and
0 deletions
1 | +package org.legrog.application; | ||
2 | + | ||
3 | +import org.legrog.entities.Country; | ||
4 | +import org.legrog.entities.CountryRepository; | ||
5 | +//import org.slf4j.Logger; | ||
6 | +//import org.slf4j.LoggerFactory; | ||
7 | + | ||
8 | +import javax.ejb.Stateless; | ||
9 | +import javax.enterprise.inject.Alternative; | ||
10 | +import javax.inject.Inject; | ||
11 | +//import java.util.List; | ||
12 | + | ||
13 | +@Stateless | ||
14 | +public class CountryServiceSpring implements CountryService { | ||
15 | + | ||
16 | + @Inject | ||
17 | + CountryRepository repository; | ||
18 | + | ||
19 | + public void addCountry(Country country) { | ||
20 | + repository.save(country); | ||
21 | + } | ||
22 | + | ||
23 | +} |
1 | +package org.legrog.presentation; | ||
2 | + | ||
3 | +import org.legrog.application.CountryService; | ||
4 | +import org.legrog.entities.Country; | ||
5 | + | ||
6 | +import javax.enterprise.context.RequestScoped; | ||
7 | +import javax.inject.Inject; | ||
8 | +import javax.inject.Named; | ||
9 | +import java.util.List; | ||
10 | + | ||
11 | +@Named | ||
12 | +@RequestScoped | ||
13 | +public class CountryBean { | ||
14 | + @Inject | ||
15 | + private CountryService service; | ||
16 | + | ||
17 | + private String countryName; | ||
18 | + public String getCountryName() { | ||
19 | + return countryName; | ||
20 | + } | ||
21 | + | ||
22 | + public void setCountryName(String countryName) { | ||
23 | + this.countryName = countryName; | ||
24 | + } | ||
25 | + | ||
26 | + public String add() | ||
27 | + { | ||
28 | + Country country = new Country(); | ||
29 | + country.setCountryName(countryName); | ||
30 | + service.addCountry(country); | ||
31 | + return "success"; | ||
32 | + } | ||
33 | +} |
... | @@ -15,6 +15,22 @@ | ... | @@ -15,6 +15,22 @@ |
15 | <from-outcome>listBooks</from-outcome> | 15 | <from-outcome>listBooks</from-outcome> |
16 | <to-view-id>/result.xhtml</to-view-id> | 16 | <to-view-id>/result.xhtml</to-view-id> |
17 | </navigation-case> | 17 | </navigation-case> |
18 | + <navigation-case> | ||
19 | + <from-outcome>addCountry</from-outcome> | ||
20 | + <to-view-id>/addCountry.xhtml</to-view-id> | ||
21 | + </navigation-case> | ||
22 | + <navigation-case> | ||
23 | + <from-outcome>listCountries</from-outcome> | ||
24 | + <to-view-id>/listCountries.xhtml</to-view-id> | ||
25 | + </navigation-case> | ||
26 | + </navigation-rule> | ||
27 | + | ||
28 | + <navigation-rule> | ||
29 | + <from-view-id>/addCountry.xhtml</from-view-id> | ||
30 | + <navigation-case> | ||
31 | + <from-outcome>success</from-outcome> | ||
32 | + <to-view-id>/listCountries.xhtml</to-view-id> | ||
33 | + </navigation-case> | ||
18 | </navigation-rule> | 34 | </navigation-rule> |
19 | 35 | ||
20 | <navigation-rule> | 36 | <navigation-rule> | ... | ... |
src/main/webapp/addCountry.xhtml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
3 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
4 | +<html xmlns="http://www.w3.org/1999/xhtml" | ||
5 | + xmlns:h="http://xmlns.jcp.org/jsf/html" | ||
6 | + xmlns:ui="http://xmlns.jcp.org/jsf/facelets" | ||
7 | + xmlns:f="http://xmlns.jcp.org/jsf/core"> | ||
8 | +<body> | ||
9 | +<h:form> | ||
10 | + <h:panelGrid columns="2"> | ||
11 | + <h:outputText value='Nom du pays'/> | ||
12 | + <h:inputText value='#{countryBean.countryName}'/> | ||
13 | + <h:outputText value='Add'/> | ||
14 | + <h:commandButton action="#{bookBean.add}" value="Add"/> | ||
15 | + </h:panelGrid> | ||
16 | +</h:form> | ||
17 | +</body> | ||
18 | +</html> |
... | @@ -18,6 +18,18 @@ | ... | @@ -18,6 +18,18 @@ |
18 | <h:outputText value="List books"/> | 18 | <h:outputText value="List books"/> |
19 | </h:commandLink> | 19 | </h:commandLink> |
20 | </li> | 20 | </li> |
21 | + <li> | ||
22 | + <h:commandLink action="addCountry"> | ||
23 | + <h:outputText value="Add country"/> | ||
24 | + </h:commandLink> | ||
25 | + </li> | ||
26 | + <!-- | ||
27 | + <li> | ||
28 | + <h:commandLink action="listCountries"> | ||
29 | + <h:outputText value="List countries"/> | ||
30 | + </h:commandLink> | ||
31 | + </li> | ||
32 | + --> | ||
21 | </ul> | 33 | </ul> |
22 | </h:form> | 34 | </h:form> |
23 | </body> | 35 | </body> | ... | ... |
src/main/webapp/listCountries.xhtml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
3 | + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
4 | +<html xmlns="http://www.w3.org/1999/xhtml" | ||
5 | + xmlns:h="http://xmlns.jcp.org/jsf/html" | ||
6 | + xmlns:ui="http://xmlns.jcp.org/jsf/facelets" | ||
7 | + xmlns:f="http://xmlns.jcp.org/jsf/core"> | ||
8 | +<body> | ||
9 | +<h:outputLabel value="Hello, world"/> | ||
10 | +</body> | ||
11 | +</html> |
-
Please register or login to post a comment