Bonsoir et bonne année à tous,
Voila J'affiche des liens dans un newspaperTable mais quand je clique sur un lien il n'y a pas de réaction, la méthode addArticle qui devrai être appelé ne semble pas l'être.
Voici le code de ma page jsp
Le code java associer
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 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD><TITLE>Welcome to JSF</TITLE> <LINK REL="STYLESHEET" HREF="./css/styles.css" TYPE="text/css"> </HEAD> <BODY> <TABLE BORDER=5 ALIGN="CENTER"> <TR><TH CLASS="TITLE">Welcome to JSF</TH></TR></TABLE> <t:outputText value="#{facade.pers}"/> <P> This is the <I>welcome.faces</I> page for the <CODE>jsf-blank</CODE> application. Replace this with your own welcome page. <P> <P> <f:view> <t:newspaperTable newspaperColumns="3" value="#{facade.tabPers}" var="per"> <f:facet name="spacer"> <f:verbatim> </f:verbatim> </f:facet> <h:column> <f:facet name="header"> <f:verbatim>Personne id</f:verbatim> </f:facet> <h:outputText value="#{per[0]}"/> </h:column> <h:column> <f:facet name="header"> <f:verbatim>Personne Name</f:verbatim> </f:facet> <t:commandLink value="#{per[1]}" action="#{facade.addArticle}"> <f:param name = "idArticle" value="#{per[0]}"/> </t:commandLink> </h:column> </t:newspaperTable> </f:view> <P> Taken from <A HREF="http://www.coreservlets.com/JSF-Tutorial/"> the coreservlets.com JSF Tutorial</A>. </BODY></HTML>
mon fichier faces-config.xml
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 package web; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Iterator; import java.util.Map; import java.awt.event.ActionEvent; import javax.faces.context.FacesContext; public class Facade { private services.DbManager mydb; private services.Factory myfact; public Facade() { mydb = new services.DbManager(); myfact = new services.Factory(mydb); } public String getName() { String name = "nom"; return (name); } public String getPers() { String lstPersonnes; ArrayList<Object> lstObjectPersonnes; System.out.println("avant"); lstObjectPersonnes = myfact.creatClassesFromDb(); System.out.println("apres"); lstPersonnes = lstObjectPersonnes.toString(); System.out.println(lstPersonnes); System.out.println(lstObjectPersonnes); return (lstPersonnes); } private String[][] getTabObject(String objectName, String idFieldName, String valueFieldName) { Class classObject; try { classObject = Class.forName("model." + objectName); } catch (Exception e) {System.out.println("dbConnect.creatClass Exception: " + e.toString()); return (null);} ArrayList<Object> lstObject; lstObject = myfact.creatClassesFromDb("Personne"); // Class tabParameterTypes[] = {String.class}; String currentGetIdMethod = "get" + idFieldName.substring(0, 1).toUpperCase() + idFieldName.substring(1); String CurrentGetValueMethod = "get" + valueFieldName.substring(0, 1).toUpperCase() + valueFieldName.substring(1); // Object tabParameterValues[] = {fieldValue}; Class objectType = object.getClass(); Method getIdMethod; Method getValueMethod; try { getIdMethod = classObject.getMethod(currentGetIdMethod); getValueMethod = classObject.getMethod(CurrentGetValueMethod); } catch (Exception e) {System.out.println("dbConnect.creatClass Exception: " + e.toString()); return (null);} Iterator<Object> it = lstObject.iterator(); String tabObject[][] = new String[lstObject.size()][2]; int i = 0; try { while (it.hasNext()) { Object object = (Object) it.next(); tabObject[i][0] = getIdMethod.invoke(object); tabObject[i][1] = getValueMethod.invoke(object); i++; } } catch (Exception e) {System.out.println("dbConnect.creatClass Exception: " + e.toString()); return (null);} } public String[][] getTabPers() { ArrayList<Object> lstObjectPersonnes; lstObjectPersonnes = myfact.creatClassesFromDb("Personne"); Iterator<Object> it = lstObjectPersonnes.iterator(); String lstPersonnes[][] = new String[lstObjectPersonnes.size()][2]; int i = 0; model.Personne pers; while (it.hasNext()) { Object o = (Object) it.next(); if (o.getClass().getName() == "model.Personne") { pers = (model.Personne)o; lstPersonnes[i][0] = pers.getId(); lstPersonnes[i][1] = pers.getNom(); } i++; } // System.out.println(lstPersonnes.toString()); // System.out.println(lstObjectPersonnes); // System.out.println (lstPersonnes[0][0]); return (lstPersonnes); } // methodName(ActionEvent) public String addArticle () { System.out.println("idArticle"); Map<String, String> genMap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); String idArticle = genMap.get("idArticle"); System.out.println("idArticle"); return ("welcome.faces"); } }
et enfin mon fichier Web.xml
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 <?xml version="1.0"?> <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"> <faces-config> <managed-bean> <managed-bean-name>sample</managed-bean-name> <managed-bean-class>coreservlets.SampleBean</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>facade</managed-bean-name> <managed-bean-class>web.Facade</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <managed-bean> <managed-bean-name>order</managed-bean-name> <managed-bean-class>coreservlets.OrderBean</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <navigation-rule> <from-view-id>/date.jsp</from-view-id> <navigation-case> <from-outcome>show-date</from-outcome> <to-view-id>/WEB-INF/results/show-date.jsp</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <from-view-id>/order.jsp</from-view-id> <navigation-case> <from-outcome>show-order</from-outcome> <to-view-id>/WEB-INF/results/show-order.jsp</to-view-id> </navigation-case> </navigation-rule> </faces-config>
Je ne pense pas que l'intégralité le code de ma page jsp et de mon fichier java soit important mais bon vu que je débute ne jsp j'ai préférer vous présenter l'intégralité de mon code.
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
135
136
137
138
139
140
141
142 <?xml version="1.0"?> <!-- * Copyright 2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * UPDATED: Marty Hall changed to use .faces suffix, * faces-config.xml filename, and servlets 2.4. --> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <!-- Extensions Filter --> <filter> <filter-name>MyFacesExtensionsFilter</filter-name> <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class> <init-param> <param-name>maxFileSize</param-name> <param-value>20m</param-value> <description>Set the size limit for uploaded files. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB </description> </init-param> </filter> <!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages --> <filter-mapping> <filter-name>MyFacesExtensionsFilter</filter-name> <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry --> <servlet-name>Faces Servlet</servlet-name> </filter-mapping> <!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.) --> <filter-mapping> <filter-name>MyFacesExtensionsFilter</filter-name> <url-pattern>/faces/myFacesExtensionResource/*</url-pattern> </filter-mapping> <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value> /WEB-INF/faces-config.xml </param-value> <description> Comma separated list of URIs of (additional) faces config files. (e.g. /WEB-INF/my-config.xml) See JSF 1.0 PRD2, 10.3.2 </description> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>client</param-value> <description> State saving method: "client" or "server" (= default) See JSF Specification 2.5.2 </description> </context-param> <context-param> <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name> <param-value>true</param-value> <description> This parameter tells MyFaces if javascript code should be allowed in the rendered HTML output. If javascript is allowed, command_link anchors will have javascript code that submits the corresponding form. If javascript is not allowed, the state saving info and nested parameters will be added as url parameters. Default: "true" </description> </context-param> <context-param> <param-name>org.apache.myfaces.PRETTY_HTML</param-name> <param-value>true</param-value> <description> If true, rendered HTML code will be formatted, so that it is "human readable". i.e. additional line separators and whitespace will be written, that do not influence the HTML code. Default: "true" </description> </context-param> <context-param> <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>org.apache.myfaces.AUTO_SCROLL</param-name> <param-value>true</param-value> <description> If true, a javascript function will be rendered that is able to restore the former vertical scroll on every request. Convenient feature if you have pages with long lists and you do not want the browser page to always jump to the top if you trigger a link or button action that stays on the same page. Default: "false" </description> </context-param> <!-- Listener, that does all the startup work (configuration, init). --> <listener> <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class> </listener> <!-- Faces Servlet Marty Hall: changed .jsf back to standard of .faces --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> <!-- Welcome files --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
je travail avec le server Tomcat 6.0.14 catalina.
Bonne Soirée ou Bonjour
Partager