Bonsoir à tous
j'ai une classe Recherche(String mot, int Indice)
comment je peux importer cette classe dans ma page JSP
en utilisant le tag
Code:
1
2
3<%@ page import="??????????????"%>
Version imprimable
Bonsoir à tous
j'ai une classe Recherche(String mot, int Indice)
comment je peux importer cette classe dans ma page JSP
en utilisant le tag
Code:
1
2
3<%@ page import="??????????????"%>
Bonjour,
L'import peut se faire en utilisant la syntaxe :
BenoitCode:<%@ page import="nom.du.package.maClasse"%>
Bonjour,
Merci mais quand je fait ça dans ma page:
il me signale une erreur que la méthode Recherche(String, int) is undefinedCode:
1
2
3
4
5 <% RowSetDynaClass rs = Recherche("Text",1).getRecherche(); %>
Bonjour,
Une classe n'est pas paramétrée.
Un constructeur peut l'être, mais ça n'est pas la façon de l'utiliser.
Lorsque tu écris:
Le compilateur voit un appel de méthode "Recherche()" puis un autre appel de méthode "getRecherche()" sur le résultat précédent.Code:Recherche("Text",1).getRecherche();
En supposant que tu veuilles instancier un objet de type Recherche, alors rajoute le mot-clef d'instanciation: new
Dans l'attente de ton retour,Code:
1
2
3 <% RowSetDynaClass rs = new Recherche("Text",1).getRecherche(); %>
Sébastien
Peux-tu fournir l'erreur exacte et le contenu de la classe Recherche.
Benoit
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
55
56 package Test; import java.io.PrintWriter; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import org.apache.commons.beanutils.RowSetDynaClass; public class Recherche { private int Type; private String Rech, SqlStr; private static RowSetDynaClass alerte; public RowSetDynaClass getRecherche (String Rech1, int Type1) { Rech= Rech1 ; Type=Type1; BDD con = new BDD(); Statement stmt; try { stmt = con.getCon().createStatement(); if (Type ==1) //Article { SqlStr="Select NOMARTICLE, NSERIE from DC_ARTIICLE where NOMARTICLE like '%" + Rech + "%' or NSERIE LIKE '%"+ Rech +"%'"; } else if (Type ==2)//Demandeur { } ResultSet rs = stmt.executeQuery(SqlStr); RowSetDynaClass rs1 = new RowSetDynaClass(rs, false); alerte=rs1; stmt.close(); con.getCon().close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return alerte; } }
l'erreurCode:
1
2
3
4
5 <% RowSetDynaClass rs = Recherche("gg",1).getRecherc(); request.setAttribute("results", rs); %>
Code:
1
2 The method Recherche(String, int) is undefined for the type __2F_AppDC_2F_WebContent_2F_RechDemandeur_2E_jsp
Mauvais appel de la méthode. Tu as 2 solutions possibles :
-Soit tu instancies ton objet Recherche dans ta jspSoit tu rends static la méthode getRecherche :Code:
1
2 Recherche recherche = new Recherche(); RowSetDynaClass result = recherche.getRecherche("gg",1);
et dans ce cas l'appel sera comme suit :Code:public static RowSetDynaClass getRecherche (String Rech1, int Type1)
En oubliant pas d'importer dans ta jsp la classe RowSetDynaClass.Code:RowSetDynaClass rs = Recherche.getRecherche("gg",1);
Merci monsieur beaucoup mais si à la place de gg je veux récupérer le contenu de inputtext?????????
Tu vas vouloir récupérer, un , deux, voire plusieurs champs formulaires et soumettre comme ça à ta classe, ceci dans ta jsp, mauvaise pratique, le principe de découplage de couches MVC veut que tu soumettes ton formulaire à une servlet, qui son traitement et retourne le résultat à la jsp, qui ne doit se charger que d'afficher. Pourquoi n'utilises tu pas des servlets?
Merci je travaille avec JSF
en plus pour afficher le <display:table
je dois le faire au niveau de ma page JSF
si je vais transformer ma classe en bean
comment je peux afficher le tableau??
Fais nous voir le code de ta page jsp et le managedBean alimentant cette page. Moi perso j'ai du mal à répondre à une question juste pour que ca marche, c'est toujours plus propre de suivre la philosophie imposée par chaque framework :mouarf:.
Ok
voici ma classe de recherche:
et voici ma page 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
55
56
57 package Test; import java.io.PrintWriter; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import org.apache.commons.beanutils.RowSetDynaClass; public class Recherche { private int Type; private String Rech, SqlStr; private static RowSetDynaClass alerte; public RowSetDynaClass getRecherche (String Rech1, int Type1) { Rech= Rech1 ; Type=Type1; BDD con = new BDD(); Statement stmt; try { stmt = con.getCon().createStatement(); if (Type ==1) //Article { SqlStr="Select NOMARTICLE, NSERIE from DC_ARTIICLE where NOMARTICLE like '%" + Rech + "%' or NSERIE LIKE '%"+ Rech +"%'"; } else if (Type ==2)//Demandeur { } ResultSet rs = stmt.executeQuery(SqlStr); RowSetDynaClass rs1 = new RowSetDynaClass(rs, false); alerte=rs1; stmt.close(); con.getCon().close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return alerte; } }
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
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 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://displaytag.sf.net" prefix="display" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%> <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="org.apache.commons.beanutils.RowSetDynaClass"%> <%@page import="Test.Recherche"%> <%@page import="java.util.Locale"%> <%@page import ="java.sql.Connection"%> <%@page import="java.sql.DriverManager"%> <%@page import="java.sql.SQLException"%> <%@page import="java.sql.Statement"%> <%@page import="java.sql.ResultSet"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <f:view> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Recherche</title> </head> <body> <h:form id="Rech"> <table border="0" cellpadding="0" cellspacing="0" width="477" style="border-collapse: collapse;width:358pt"> <colgroup> <col width="120" style="width: 90pt"><col width="80" style="width: 60pt"> <col width="169" style="width: 127pt"><col width="108" style="width: 81pt"> </colgroup> <tr height="34" style="height: 25.5pt"> <td height="34" width="220" style="height: 25.5pt; width: 90pt; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-left: medium none; border-right: medium none; border-top: .5pt solid #FFCC66; border-bottom: .5pt solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px"> <b><font face="Calibri" size="4">Mot recherché:</font></b></td> <td colspan="3" width="357" style="width: 268pt; text-align: center; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-left: medium none; border-right: .5pt solid #FFCC66; border-top: .5pt solid #FFCC66; border-bottom: .5pt solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px"> <h:inputText size="40" style=" width : 403px;" id="rech"/></td> </tr> <tr height="9" style="height: 6.75pt"> <td height="9" style="height: 6.75pt; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-left: medium none; border-right: .5pt solid #FFCC66; border-top: medium none; border-bottom: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> </tr> <tr height="257" style="height: 192.75pt"> <td colspan="4" height="257" style="height: 192.75pt; text-align: cleft; vertical-align: top; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-left: .5pt solid #FFCC66; border-right: .5pt solid #FFCC66; border-top: medium none; border-bottom: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> <% Recherche Rech= new Recherche(); RowSetDynaClass rs = Rech.getRecherche("gg",1); request.setAttribute("results", rs); %> <display:table name="requestScope.results.rows" /> </td> </tr> <tr height="8" style="height: 6.0pt"> <td height="8" style="height: 6.0pt; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-left: medium none; border-right: .5pt solid #FFCC66; border-top: medium none; border-bottom: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> </tr> <tr height="38" style="height: 28.5pt"> <td colspan="3" height="38" style="height: 28.5pt; text-align: center; vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; white-space: nowrap; border-left: .5pt solid #FFCC66; border-right: medium none; border-top: .5pt solid #FFCC66; border-bottom: .5pt solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px"> </td> <td style="vertical-align: middle; color: black; font-size: 11.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; text-align: general; white-space: nowrap; border-left: medium none; border-right: .5pt solid #FFCC66; border-top: .5pt solid #FFCC66; border-bottom: .5pt solid #FFCC66; padding-left: 1px; padding-right: 1px; padding-top: 1px"> <h:commandButton style=" width : 96px; float:right" value="Valider" id="Rech3"/></td> </tr> </table> </h:form> </body> </html> </f:view>
Tu vois comment ca marce JSF globalement? les déclarations d'actions, managedBeans dans le faces-config?
il m'affiche bien le résultat dans ma page
mais à codition de fixer la valeur moir je veux seulement la récuper dans champ Inputtext
Ce n'est pas là ma question.Tu ne fais aucunement du JSF, et visiblement tu n'as pas envie d'apprendre, il me semble qu'on avait déjà débattu de ça, visiblement tu n'as toujours pas eu le temps de plonger dans le fonctionnement de JSF, car tu ne poserais pas cette question. C'est le principe de base même JSF. Alors soit tu nous dis que tu n'es pas entrain de faire du JSF et donc c'est du classique jsp<==>Servlet, et là dans ce cas on té répondra, soit c'est du JSF et tu vas te former ici
C'est bon
je vais transformer ma classe en bean et je vais la déclarer dans faces-config
(c'est faisable pour moi)
je vais afficher le résultat dans
<rich:subTable>
mais commen le faire??
L'exemple de l'alimentation d'un tableau jsp par un managedBean est aussi traité dans le lien que je t'ai envoyé (fichier fin.jsp).Bon courage
Oui Merci mais
comment remplir ma table à partir de ma base de données????????