IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Struts 1 Java Discussion :

[Débutant] selectionner une ligne d'un tableau


Sujet :

Struts 1 Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 2
    Par défaut [Débutant] selectionner une ligne d'un tableau
    bonsoir je suis débutant et je travail sur un projet de fin etude avec struts ma question est comment puis-je selectionner une ligne avec un bouton radio d'une liste et recuperer la selection sur un formulaire pour faire une modification.

    j'ai une class ListeSocieteAction

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    public class ListeSocieteAction extends Action{
     
    	public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)
    			throws IOException, ServletException, SQLException {
     
    			InscriptionSocieteForm inscritForm = (InscriptionSocieteForm) form;
    			Statement st = null;
    			ResultSet rs = null;
    			String requête = null;
     
    			ArrayList list= new ArrayList();
     
    			// obtenir une connexion
     
    				 Connection cnx = null;
    		         try {
    		             Class.forName("org.postgresql.Driver");
    		             cnx = DriverManager.getConnection("jdbc:postgresql:xxxx","xxxx","xxxxx");
    						System.out.println("Connexion à la base \"xxxxx\" réussie");
    						}
    		         catch (Exception e) 
    		        	    {
    		         	System.out.println("La connexion est impossible<br>");
    		        		System.out.println(e.toString());
    						}
     
    			    // préparer la requête SQL
    				requête = "select n_siret,nom_societe,nom_gerant,mot_passe,n_voi,qtq,voi,complement,commune,ville,telephone from societe order by n_siret";
    				// l'exécuter
    				st = cnx.createStatement();
    				rs = st.executeQuery(requête);
     
    				// exploiter les résultats
    				while (rs.next()) {
     
    				// enregistrer la ligne courante
    				Societe alSociete = new Societe();
     
    				alSociete.setNSiret(rs.getString("n_siret"));
    				alSociete.setNomSociete(rs.getString("nom_societe")); 
    				alSociete.setNomGerant(rs.getString("nom_gerant"));
    				alSociete.setMotPasse(rs.getString("mot_passe")); 
    				alSociete.setNVoi(rs.getString("n_voi"));
    				alSociete.setQtq(rs.getString("qtq"));
    				alSociete.setVoi(rs.getString("voi"));
    				alSociete.setComplement(rs.getString("complement"));
    				alSociete.setCommune(rs.getString("commune"));
    				alSociete.setVille(rs.getString("ville"));
    				alSociete.setTelephone(rs.getString("telephone"));
     
    				list.add(alSociete);
     
    				}
     
    				// libérer les ressources
    				rs.close();
    				st.close();
     
    					// on libère la connexion
    					try {
    					cnx.close();
    					} catch (Exception ignored) {
    					}
    				// c'est bon
    					request.setAttribute("listSociete", list);
    					return mapping.findForward("afficherListeSociete");
    				//execute
    	}	
     
    }	 //classe


    ma liste jsp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
     
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
     
     
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
    <body>
    <h3>Liste des Societ&eacute;s</h3><br><br>
     
        <table border="1" align="center" bordercolor="#000000">
    <thead>
                    <tr>
                        <th><div align="center">Selection</div></th>
                        <th><div align="center">Num&eacute;ro de Siret</div></th>
                        <th><div align="center">Nom de la Societ&eacute;</div></th>
                        <th><div align="center">Nom du G&eacute;rant</div></th>
                        <th><div align="center">Mot de passe</div></th>
                        <th><div align="center">Num&eacute;ro de voi</div></th>
                        <th><div align="center">Qtq</div></th>
                        <th><div align="center">Voi</div></th>
                        <th><div align="center">Compl&eacute;ment</div></th>
                        <th><div align="center">Commune</div></th>
                        <th><div align="center">Ville</div></th>
    					<th><div align="center">T&eacute;l&eacute;phone</div></th>
                    </tr>
                </thead>
                <tbody>
                    <logic:iterate  name="listSociete" id="alSociete">
                      <tr>
                        <td><div align="center">
                          <td><input type="radio" name="radio" id="radio" value="radio" /></div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="NSiret"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="nomSociete"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="nomGerant"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="motPasse"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="NVoi"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="qtq"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="voi"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="complement"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="commune"/>
                        </div></td>
                        <td><div align="center">
                          <bean:write name="alSociete" property="ville"/>
                        </div></td>
                        <td><div align="center">
                        <bean:write name="alSociete" property="telephone"/>
                        </div></td>
    				</logic:iterate>
                </tbody>
            </table>
     
         <input type="button" name="modifier" value="modifier"><br>
     
    </body>
    </html>

  2. #2
    Expert confirmé

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Par défaut
    Remplace cette balise :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <input type="radio" name="radio" id="radio" value="radio" />
    par celle-ci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <html:radio property="numSiretSelected" idName="alSociete" value="NSiret"/>
    sans oublier de mettre le tag logic:iterate dans un tag html:form et de définir la propriété numSiretSelected dans l'ActionForm avec getter et setter.

    Ainsi, au submit du formulaire, la propriété numSiretSelected de l'ActionForm aura pour valeur le numéro de Siret de la société sélectionnée.

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 2
    Par défaut
    merci pour la réponse rapide je vais testé ca

Discussions similaires

  1. [MySQL] Comment afficher une ligne d'un tableau dans un formulaire en la selectionnant
    Par eddycool dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 13/05/2009, 15h49
  2. Réponses: 6
    Dernier message: 13/05/2009, 15h26
  3. [Débutant] ajout d'une ligne d'un tableau dans IE
    Par zais_ethael dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 26/06/2008, 02h59
  4. [Débutante] Atteindre une ligne aléatoire dans un tableau
    Par rosanne dans le forum Macros et VBA Excel
    Réponses: 9
    Dernier message: 29/10/2007, 13h05
  5. [HTML]Débutant-Suppression d'une ligne dans un tableau
    Par Kotik dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 19/07/2006, 11h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo