Bonjour,
J'ai un problème avec une JSP qui contient un tableau d'élève je souhaiterais que lorsque je clique sur une ligne ça m'ouvre une fiche élève avec tous les renseignement.
J'ai donc besoin de l'identifiant de l'élèves.
Voici ce que j'ai fait
Dans mon struts config
1 2 3 4 5 6 7
| <form-beans>
//Je precise que je sais pas si j'en ai besoin car je récupère pas vraiment des données d'un formulaire.
<form-bean name="formDetailEleve" type="nfe114.projet.forms.formDetailEleve"/>
<action path="/detailEleve" type="projet.actions.ActionDetailEleve">
<forward name="success" path="/vueDetailEleve.jsp"/>
</action> |
mon formDetailEleve
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projet.forms;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
/**
*
* @author sebastien
*/
public class formDetailEleve extends org.apache.struts.action.ActionForm {
private String nom;
private String prenom;
private String Sexe;
private String categorie;
private int age;
private String permis1;
private String permis2;
private int nbreHeure1;
private int nbreHeure2;
private int idEleve;
/**
*
*/
public formDetailEleve() {
super();
// TODO Auto-generated constructor stub
}
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param request The HTTP Request we are processing.
* @return
*/
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if (getNom() == null || getNom().length() < 1) {
errors.add("name", new ActionMessage("error.name.required"));
// TODO: add 'error.name.required' key to your resources
}
return errors;
}
/**
* @return the nom
*/
public String getNom() {
return nom;
}
/**
* @param nom the nom to set
*/
public void setNom(String nom) {
this.nom = nom;
}
/**
* @return the prenom
*/
public String getPrenom() {
return prenom;
}
/**
* @param prenom the prenom to set
*/
public void setPrenom(String prenom) {
this.prenom = prenom;
}
/**
* @return the Sexe
*/
public String getSexe() {
return Sexe;
}
/**
* @param Sexe the Sexe to set
*/
public void setSexe(String Sexe) {
this.Sexe = Sexe;
}
/**
* @return the categorie
*/
public String getCategorie() {
return categorie;
}
/**
* @param categorie the categorie to set
*/
public void setCategorie(String categorie) {
this.categorie = categorie;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the permis1
*/
public String getPermis1() {
return permis1;
}
/**
* @param permis1 the permis1 to set
*/
public void setPermis1(String permis1) {
this.permis1 = permis1;
}
/**
* @return the permis2
*/
public String getPermis2() {
return permis2;
}
/**
* @param permis2 the permis2 to set
*/
public void setPermis2(String permis2) {
this.permis2 = permis2;
}
/**
* @return the nbreHeure1
*/
public int getNbreHeure1() {
return nbreHeure1;
}
/**
* @param nbreHeure1 the nbreHeure1 to set
*/
public void setNbreHeure1(int nbreHeure1) {
this.nbreHeure1 = nbreHeure1;
}
/**
* @return the nbreHeure2
*/
public int getNbreHeure2() {
return nbreHeure2;
}
/**
* @param nbreHeure2 the nbreHeure2 to set
*/
public void setNbreHeure2(int nbreHeure2) {
this.nbreHeure2 = nbreHeure2;
}
/**
* @return the idEleve
*/
public int getIdEleve() {
return idEleve;
}
/**
* @param idEleve the idEleve to set
*/
public void setIdEleve(int idEleve) {
this.idEleve = idEleve;
}
} |
Mon ActionDetailEleve
System.out.println("l id est : "+request.getParameter("idEleve"));
et enfin ma JSP
qui récupère la liste des élèves
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
| <%--
Document : vueChercherEleve
Created on : 25 juin 2011, 21:29:00
Author : sebastien
--%>
<%@page import="projet.entites.Eleves"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.Collection"%>
<%@include file="Header.jsp" %>
<jsp:useBean id="eleve" scope="request" class="Collection<Eleves>" />
<H1>Eleves</H1>
<div class="centre">
<table >
<th>Nom</th>
<th>Prénom</th>
<th>type de permis</th>
<th>Numémero passage</th>
<th>nbre heures</th>
<th>modifier</th>
<% for(Eleves elvs : eleve){ %>
<tr>
<input type="hidden" name="idEleve" value="<%=elvs.getIdEleve()%>">
<td><%=elvs.getNom()%></td>
<td><%=elvs.getPrenom()%></td>
<td><%=elvs.getCat()%></td>
<td><%=elvs.getPermis().getNumPassage()%></td>
<td><%=elvs.getPermis().getNombreHeure()%></td>
<td ><html:link action="detailEleve">voir</html:link></td>
</tr>
<%}%>
</table>
</div>
<%@include file="footer.jsp" %> |
je récupère toujours un IdEleve null et j'ai une erreur quand je vais sur vueDetailEleve ça me dit qu'il peut pas instancier la classe élève.
Voici donc ma jsp détailEleve
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| <%--
Document : vueDetailEleve
Created on : 26 juin 2011, 08:28:21
Author : sebastien
--%>
<%@page import="projet.entites.Moniteur"%>
<%@page import="java.util.Collection"%>
<%@page import="projet.entites.Eleves"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@include file="Header.jsp" %>
<h1></h1>
<hr><%--Non respect du W3C "</hr>"--%>
<div class="centre">
<jsp:useBean id="elv" scope="request" class="Eleves" />
<div class="styleFormulaire" >
<html:form >
<p>
<label for="nom">Nom:</label>
<html:text property="nom" value="" size="30" />
<br>
<label for="prenom">Prénom:</label>
<html:text property="prenom" value="" size="30" />
</p>
<p>
<label for="sexe">Sexe:</label>
<html:select property="sexe" >
<html:option value="H">H</html:option>
<html:option value="F">F</html:option>
</html:select>
<br>
<label for="categorie">Catégorie:</label>
<html:select property="categorie" >
<html:option value="AAC">AAC</html:option>
<html:option value="B">B</html:option>
</html:select>
<br>
<label for="age">Age:</label>
<html:text property="age" value="" size="15" />
<br>
<label for="permis1">Premier permis:</label>
<html:text property="permis1" value="" size="15" />
<br>
<label for="nbrHeure1">Nbre Heures:</label>
<html:text property="nbrHeure1" value="" size="15" />
<br>
<label for="permis2">Second permis</label>
<html:text property="permis2" value="" size="15" />
<br>
<label for="nbrHeure2">NbreHeure:</label>
<html:text property="nbrHeure2" value="" size="15" />
</p>
<input type="submit" value="ok" /> <a href="#">Annuler</a>
</html:form>
</div><!--Fin style formulaire-->
</div><!--Fin div centrage-->
<%@include file="footer.jsp" %> |
Merci pour voter aide
Partager