recupérer les données d'un formulaire dans une autre page en utilisant rich:datatable
Bonjour, la communauté
J'ai deux pages test3.jsp et test4.jsp Dans test3 j'ai un formulaire.
Quant on clique sur le bouton il doit me rediriger vers la page test4.jsp avec les informations recuielli dans un datatable.
Maintemant quand je clique sur le bouton rien ne se passe
test3.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>test3</title>
</head>
<body>
<f:view>
<rich:panel style="border:0;width:60%;text-align:center">
<h:form >
<rich:panel>
<table>
<tr>
<td>
<h:outputText value="Nom" id="nm" style="font-weight:bold;" />
<h:inputText value="#{person.name}" id="name" />
</td>
<td>
<h:outputText value="Prenom" id="pm" style="font-weight:bold;" />
<h:inputText value="#{person.prenom}" id="prenom" />
</td>
</tr>
<tr>
<td>
<h:outputText value="Ville" id="vl" style="font-weight:bold;" />
<h:selectOneMenu value="#{person.ville}">
<f:selectItem itemLabel="Dakar" itemValue="Dakar"/>
<f:selectItem itemLabel="Thies" itemValue="Thies"/>
<f:selectItem itemLabel="Saint-Louis" itemValue="Saint-Louis"/>
</h:selectOneMenu>
</td>
<td>
<h:outputText value="Adresse" id="adr" style="font-weight:bold;" />
<h:inputText value="#{person.adresse}" id="adresse" />
</td>
</tr>
<tr>
<td>
<h:commandButton value="Valider" actionListener="#{person.valid}"/>
</td>
</tr>
</table>
</rich:panel>
</h:form>
</rich:panel>
</f:view>
</body>
</html> |
la page test4.jsp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
<f:verbatim>
<br/><br/>
</f:verbatim>
<rich:dataTable border="1" var="pers" value="#{person.listpers}">
<rich:column>
<f:facet name="header">Nom</f:facet>
<h:outputText value="#{pers.name}" />
</rich:column>
<rich:column>
<f:facet name="header">Prenom</f:facet>
<h:outputText value="#{pers.prenom}" />
</rich:column>
<rich:column >
<f:facet name="header">Ville</f:facet>
<h:outputText value="#{pers.ville}" />
</rich:column>
<rich:column>
<f:facet name="header">Adresse</f:facet>
<td><h:outputText value="#{pers.adresse}" /></td>
</rich:column>
</rich:dataTable>
</h:form>
</f:view>
</body>
</html> |
La classe bean person
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| import java.util.List;
import javax.faces.event.ActionEvent;
public class person {
private String name;
private String prenom;
private String ville;
private String adresse;
private List<client> listpers;
//les methodes getters et setters
public List<client> getListpers() {
return listpers;
}
public void setListpers(List<client> listpers) {
this.listpers = listpers;
}
public String valid(ActionEvent evt){
client cl=new client();
cl.setName(getName());
cl.setPrenom(getPrenom());
cl.setVille(getVille());
cl.setAdresse(getAdresse());
listpers.add(cl);
return "valid";
}
} |
la classe client
Code:
1 2 3 4 5 6 7 8
| public class client {
private String name;
private String prenom;
private String ville;
private String adresse;
//les methodes getters et setters
} |
une partie de faces-config.xml qui concerne la redirection
Code:
1 2 3 4 5 6 7
| <navigation-rule>
<from-view-id>/test3.jsp</from-view-id>
<navigation-case>
<from-outcome>valid</from-outcome>
<to-view-id>/test4.jsp</to-view-id>
</navigation-case>
</navigation-rule> |