Bonjour tout le monde
je voulai savoir est ce que vous avez une idee sur comment utiliser AutoComplet (comme google suggest) dans struts 3 est ce qu'il ya cette possibilité ?
Merci
Bonjour tout le monde
je voulai savoir est ce que vous avez une idee sur comment utiliser AutoComplet (comme google suggest) dans struts 3 est ce qu'il ya cette possibilité ?
Merci
Bonjour,
Pour reprendre les choses dans l'ordre...
Déjà : Struts 3
Ensuite : oui, il existe des méthodes pour faire de l'autocomplétion avec struts. Mais, qu'est-ce tu veux qu'on te dise de plus. On va pas te pondre quelque chose sans rien savoir ce que tu fais.
Renseigne toi d'abord, regarde des exemples, essaye par toi-même, et si tu n'y arrives pas, alors viens là avec ton bout de code, et là, on sera plus en mesure de t'aider...
Voila ma classe AnnotBean
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 package ma.struts.myPack.admin; import java.io.Serializable; public class AnnotBean implements Serializable{ private Integer id; private String libelle; private String type; private String partage; private String annotateur; private String composant; public String getAnnotateur() { return annotateur; } public void setAnnotateur(String currentAnnot) { this.annotateur = currentAnnot; } public String getComposant() { return composant; } public void setComposant(String composant) { this.composant = composant; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getLibelle() { return libelle; } public void setLibelle(String libelle) { this.libelle = libelle; } public String getPartage() { return partage; } public void setPartage(String partage) { this.partage = partage; } public String getType() { return type; } public void setType(String currentType) { this.type = currentType; } }
Voila mon ListAnnotBean
mon ListAnnotBeanDAO
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 package ma.struts.myPack.admin; import java.io.Serializable; public class AnnotBean implements Serializable{ private Integer id; private String libelle; private String type; private String partage; private String annotateur; private String composant; public String getAnnotateur() { return annotateur; } public void setAnnotateur(String currentAnnot) { this.annotateur = currentAnnot; } public String getComposant() { return composant; } public void setComposant(String composant) { this.composant = composant; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getLibelle() { return libelle; } public void setLibelle(String libelle) { this.libelle = libelle; } public String getPartage() { return partage; } public void setPartage(String partage) { this.partage = partage; } public String getType() { return type; } public void setType(String currentType) { this.type = currentType; } }
la class AfficherListAnnotAction
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 package ma.struts.myPack.admin; import java.sql.Connection; import java.sql.ResultSet; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.sql.DataSource; import ma.struts.myPack.admin.AnnotBean; public class ListAnnotBeanDAO { private final static String NOM_RESOURCE_JDBC = "java:comp/env/jdbc/myDB"; public ListAnnotBean remplirListAnnot() { final ListAnnotBean myLstFindAnnotBean = new ListAnnotBean(); try { final Context myContext = new InitialContext(); final DataSource myDataSource = (DataSource) myContext.lookup(NOM_RESOURCE_JDBC); final ArrayList<AnnotBean> myLstAnnot = new ArrayList<AnnotBean>(); final Connection myConnection = myDataSource.getConnection(); final Statement myStatement = myConnection.createStatement(); final Statement myStatement2 = myConnection.createStatement(); final Statement myStatement3 = myConnection.createStatement(); final ResultSet myResultSet = myStatement.executeQuery("SELECT * FROM ANNOTATIONS"); while (myResultSet.next()) { final AnnotBean myAnnotBean = new AnnotBean(); final Integer currentId = myResultSet.getInt("ID"); final String currentNom = myResultSet.getString("LIBELLE"); final Integer currentType1 = myResultSet.getInt("TYPE"); final ResultSet myResultSet1 = myStatement2.executeQuery("SELECT * FROM TYPE_ANNOTATION WHERE ID="+ currentType1 +""); while (myResultSet1.next()) { final String currentType = myResultSet1.getString("LIB_TYPE"); myAnnotBean.setType(currentType); } final String currentPartage = myResultSet.getString("PARTAGE"); final Integer currentAnnot1 = myResultSet.getInt("ANNOTATEUR"); final ResultSet myResultSet3 = myStatement3.executeQuery("SELECT * FROM ANNOTATEUR WHERE ID="+ currentAnnot1 +""); while (myResultSet3.next()) { final String currentAnnot = myResultSet3.getString("LOGIN"); myAnnotBean.setAnnotateur(currentAnnot); } final String currentCompo = myResultSet.getString("COMPOSANT"); myAnnotBean.setId(currentId); myAnnotBean.setLibelle(currentNom); myAnnotBean.setPartage(currentPartage); myAnnotBean.setComposant(currentCompo); myLstAnnot.add(myAnnotBean); } myLstFindAnnotBean.setListeAnnot(myLstAnnot); } catch (NamingException e) { // affichage de l'erreur produite en cas d'exception relative au nommage e.printStackTrace(); // enregistremenet de l'erreur dans l'instance myLstFindPersoBean s'il en a myLstFindAnnotBean.setErreur("NamingException : " + e.getMessage()); } catch (SQLException e) { // affichage de l'erreur produite en cas d'exception relative à la requete SQL e.printStackTrace(); // enregistremenet de l'erreur dans l'instance myLstFindPersoBean s'il en a myLstFindAnnotBean.setErreur("NamingException : " + e.getMessage()); } return myLstFindAnnotBean; } public String supprimerAnnot(final Integer valId) { try { final Context myContext = new InitialContext(); final DataSource myDataSource = (DataSource) myContext.lookup(NOM_RESOURCE_JDBC); final Connection myConnection = myDataSource.getConnection(); // supprimer l'enregistrement final PreparedStatement myPreparedStatementDelete = myConnection.prepareStatement("DELETE FROM ANNOTATIONS WHERE id=?"); myPreparedStatementDelete.setInt(1, valId); myPreparedStatementDelete.executeUpdate(); return null; } catch (NamingException e) { return "NamingException : " + e.getMessage(); } catch (SQLException e) { return "SQLException : " + e.getMessage(); } } }
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 package ma.struts.myPack.admin; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ma.struts.myPack.admin.ListPersoBean; import ma.struts.myPack.admin.ListPersoBeanDAO; import org.apache.struts.Globals; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; import org.apache.struts.action.ActionMessages; public class AfficherListAnnotAction extends Action{ public ActionForward execute(final ActionMapping pMapping, ActionForm pForm, final HttpServletRequest request, final HttpServletResponse pReponse) { // Récupère les enregistrement de la base de données final ListAnnotBeanDAO myLstAnnotDAO = new ListAnnotBeanDAO(); final ListAnnotBean myListFindAnnot = myLstAnnotDAO.remplirListAnnot(); if(myListFindAnnot.getErreur() == null) { // Stockage des informations lues dans la requête request.setAttribute("LISTE_ANNOTATIONS", myListFindAnnot.getListeAnnot()); // S'il n'y a pas d'erreurs lors de la lecture desenregistrement de la base de données, on retourne le forward "succes" return pMapping.findForward("succes"); } else { final ActionMessages myErr = getErrors(request); final ActionMessage myActionMsg = new ActionMessage(myListFindAnnot.getErreur(), false); myErr.add(Globals.ERROR_KEY, myActionMsg); saveErrors(request, myErr); // S'il y a des erreurs lors de la lecture des enreghistrements de la base de données, on retourne le forward "erreur" return pMapping.findForward("erreur"); } }}
Ma page JSP
NB: mon code fonction bien avant d'ajouter autoCompleter le code suivant
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 <table border="1"> <thead> <tr> <th><bean:message key="colonne.idPerso"/></th> <th><bean:message key="colonne.nomPerso"/></th> <th><bean:message key="colonne.prenomPerso"/></th> <th><bean:message key="colonne.loginPerso"/></th> <th><bean:message key="colonne.groupePerso"/></th> <th><bean:message key="colonne.supprimer"/></th> </tr> </thead> <tbody> <logic:iterate id="adminBean" name="LISTE_ANNOTATEUR" type="ma.struts.myPack.admin.AdminBean"> <tr> <td><b><bean:write name="adminBean" property="id"/></b></td> <td width="160"><b><bean:write name="adminBean" property="nom"/></b></td> <td width="160"><b><bean:write name="adminBean" property="prenom"/></b></td> <td width="160"><b><font color="blue"><bean:write name="adminBean" property="login"/></font></b></td> <td width="160"><b><bean:write name="adminBean" property="groupe"/></b></td> <sx:autocompleter name="adminBean" value="prenom" autoComplete="true" keyName="prenom" keyValue="prenom" listValue="prenom"/> </tr> </logic:iterate> </tbody> </table>
mon code permet d'afficher un tableau qui contient une liste d'annotateur.. aprés je veux faire une zone de text avec autocomplet sur les prenom des annotateurs est ce que vous avez des idees ....
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 <sx:autocompleter name="adminBean" value="prenom" autoComplete="true" keyName="prenom" keyValue="prenom" listValue="prenom"/>
Merci
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager