Bonsoir,

Alors j'essaye de créer une liste déroulante pour laquelle je dois afficher les attributs de chaque objet (Par exemple : Si je clique sur le nom d'une entreprise dans le select, ça doit afficher le nom, le numéro, le mail... et changer les informations dynamiquement en fonction du nom de l'entreprise) .

Je vous mets l'exemple ci - dessous d'un projet que j'avais développé en PHP et sur lequel j'ai pu créer une liste déroulante (en cliquant sur un nom d'une plante, ça m'affichait le nom, la photo et la description) :
Nom : listepl.PNG
Affichages : 1081
Taille : 140,5 Ko

Actuellement, j'ai pu afficher les enregistrements d'une table dans un tableau (j'utilise PostgreSQL et TomCat server). Et pour mon projet, j'adopte une architecture MVC.

Je vous mets les fichiers principaux que j'utilise pour pouvoir afficher la table voulue dans un tableau :

un aperçu:

Nom : entrepriserv.PNG
Affichages : 1046
Taille : 11,9 Ko


Dans mon package bean :

Entreprise.java :

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
 
package com.beans;
 
public class Entreprise{
	private String ident;
    private String noment;
    private String adresseent;
    private String telent;
 
 
 
    public String getnoment() {
		return noment;
	}
	public void setnoment(String pnoment) {
		noment = pnoment;
	}
	public String getadresseent() {
		return adresseent;
	}
	public void setadresseent(String padresseent) {
		adresseent = padresseent;
	}
	public String gettelent() {
		return telent;
	}
	public void settelent(String ptelent) {
		telent = ptelent;
	}
 
	public String getident() {
		return ident;
	}
	public void setident(String pident) {
		ident = pident;
	}  
}
Dans mon package dao (le dao et daoImpl) :

EntrepriseDaoImpl.java :

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
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
 
 
package com.dao;
 
import static com.dao.DAOUtilitaire.fermeturesSilencieuses;
import static com.dao.DAOUtilitaire.initialisationRequetePreparee;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
 
import com.beans.Entreprise;
 
public class EntrepriseDaoImpl implements EntrepriseDao {
 
    private static final String SQL_SELECT_PAR_ID = "SELECT * FROM Entreprise where ident=?";
    private static final String SQL_SELECT = "SELECT * FROM Entreprise";
    private static final String SQL_INSERT           = "INSERT INTO Entreprise (ident,noment,adresseent,telent) VALUES (?, ?, ?, ?)";
 
    private DAOFactory          daoFactory;
 
    EntrepriseDaoImpl( DAOFactory daoFactory ) {
        this.daoFactory = daoFactory;
    }
 
 
 
    @Override
    public Entreprise trouver( String id ) throws DAOException {
        return trouver( SQL_SELECT_PAR_ID, id );
    }
 
    @Override
    public ArrayList<Entreprise> trouverTous() throws DAOException {
    	  	return trouverTous( SQL_SELECT);
    }
 
 
    @Override
    public void creer( Entreprise entreprise ) throws DAOException {
        Connection connexion = null;
        PreparedStatement preparedStatement = null;
        ResultSet valeursAutoGenerees = null;
 
        try {
            connexion = daoFactory.getConnection();
            preparedStatement = initialisationRequetePreparee( connexion, SQL_INSERT, true, entreprise.getident(), entreprise.getnoment(), entreprise.getadresseent(),entreprise.gettelent());
            int statut = preparedStatement.executeUpdate();
            if ( statut == 0 ) {
                throw new DAOException( "Échec de la création de la station, aucune ligne ajoutée dans la table." );
            }
            valeursAutoGenerees = preparedStatement.getGeneratedKeys();
            if ( valeursAutoGenerees.next() ) {
            	entreprise.setident(  valeursAutoGenerees.getString( 1 ) );
            } else {
                throw new DAOException( "Échec de la création de la station en base, aucun ID auto-généré retourné." );
            }
        } catch ( SQLException e ) {
            throw new DAOException( e );
        } finally {
            fermeturesSilencieuses( valeursAutoGenerees, preparedStatement, connexion );
        }
    }
 
 
    private Entreprise trouver( String sql, Object... objets ) throws DAOException {
        Connection connexion = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        Entreprise entreprise = null;
 
        try {
 
            connexion = daoFactory.getConnection();
 
            preparedStatement = initialisationRequetePreparee( connexion, sql, false, objets );
            resultSet = preparedStatement.executeQuery();
 
            if ( resultSet.next() ) {
            	entreprise = map( resultSet );
            }
        } catch ( SQLException e ) {
            throw new DAOException( e );
        } finally {
            fermeturesSilencieuses( resultSet, preparedStatement, connexion );
        }
 
        return entreprise;
    }
 
 
    private ArrayList<Entreprise> trouverTous( String sql, Object... objets ) throws DAOException {
        Connection connexion = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        Entreprise loueur = null;
        ArrayList<Entreprise> listestation=new ArrayList<Entreprise>();
 
        try {
 
            connexion = daoFactory.getConnection();
 
            preparedStatement = initialisationRequetePreparee( connexion, sql, false, objets );
            resultSet = preparedStatement.executeQuery();
 
            while ( resultSet.next() ) {
 
            	loueur = map( resultSet );
                System.out.println("nom:"+ loueur.getnoment());
                listestation.add(loueur);
            }
        } catch ( SQLException e ) {
            throw new DAOException( e );
        } finally {
            fermeturesSilencieuses( resultSet, preparedStatement, connexion );
        }
 
        return listestation;
    }
 
 
 
    private static Entreprise map( ResultSet resultSet ) throws SQLException {
    	Entreprise entreprise = new Entreprise();
    	entreprise.setident(resultSet.getString( "ident" ) );
    	entreprise.setadresseent(resultSet.getString("adresseent"));
    	entreprise.setnoment( resultSet.getString( "noment" ) );
    	entreprise.settelent( resultSet.getString( "telent" ) );
        return entreprise;
    }
 
}

EntrepriseDao.java :

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
 
package com.dao;
 
import java.util.ArrayList;
 
import com.beans.Entreprise;
 
public interface EntrepriseDao {
 
    void creer( Entreprise entreprise ) throws DAOException;
 
    Entreprise trouver( String noment ) throws DAOException;
 
    ArrayList<Entreprise> trouverTous() throws DAOException;
 
}
la JSP listeentreprises.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
 
<%@ page pageEncoding="UTF-8" %>
<%@page import="com.beans.Entreprise"%>
<%@page import="java.util.ArrayList"%>
 
 
 
<!DOCTYPE html>
 
<html>
 
    <head>
 
        <meta charset="utf-8" />
 
        <title>Liste des entreprises</title>
 
        <link type="text/css" rel="stylesheet" href="form.css" />
 
    </head>
 
    <body>
 
	Liste des entreprises:
       <table border=1>
       <tr>
       		<td> id </td>
       		<td> Nom Entreprise </td>
       		<td> Téléphone </td>
       		<td> Adresse de l'entreprise </td>
 
       </tr>
        <% ArrayList<Entreprise> listeentreprises =(ArrayList<Entreprise>) request.getAttribute("listeentreprises"); %>
 
       <% if (listeentreprises!=null)
    	   {
    	   	for (Entreprise inscrit : listeentreprises) { %>
 
 
       		<tr>
 
       			<td>
 
    				<% out.println(inscrit.getident()); %>
    			</td>
    			<td>
 
    				<% out.println(inscrit.getnoment()); %>
    			</td>
    			<td>
 
    				<% out.println(inscrit.gettelent()); %>
    			</td>
 
    			<td>
 
    				<% out.println(inscrit.getadresseent()); %>
    			</td>
 
 
 
      		 </tr>
 
	   <%		}
    	   }
	   %>
 
 
 
       </table>
       <li><a href = "index.html"> Retourner au Menu</a></li>
 
 
    </body>
 
</html>
Et voici un aperçu de mon arborescence :


Nom : arborescence.PNG
Affichages : 1023
Taille : 24,7 Ko


Merci d'avance pour les futures aides et conseils que vous me donnerez !