Et si tu renommes id_type_alarm en idTypeAlarm, de façon à respecter les conventions de nommage java, avec les méthodes getIdTypeAlarm et setIdTypeAlarm, est-ce que ça marche mieux ?
Et si tu renommes id_type_alarm en idTypeAlarm, de façon à respecter les conventions de nommage java, avec les méthodes getIdTypeAlarm et setIdTypeAlarm, est-ce que ça marche mieux ?
Modératrice Java - Struts, Servlets/JSP, ...
Je viens de me rendre compte que je n'avais pas regardé dans le détail ton bean AlarmView.
Normalement, tu devrais avoir défini chaque attribut comme par exemple :
Et les méthodes getTypeAlarm et setTypeAlarm devraient être les suivantes :
Code : Sélectionner tout - Visualiser dans une fenêtre à part private Integer idTypeAlarm;
idem pour tous les attributs de ton bean.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 public Integer getIdTypeAlarm() { return idTypeAlarm ; } public void setIdTypeAlarm(Integer idTypeAlarm) { this.idTypeAlarm=idTypeAlarm ; }
Et idem dans ton ActionForm.
Modératrice Java - Struts, Servlets/JSP, ...
Et oui, c'est encore moi.
En fait, pourrais-tu poster aussi le code de la classe AlarmValue ?
Modératrice Java - Struts, Servlets/JSP, ...
le code alarmEditAction est: ********alarmEditAction***********
et *************alarmValue*******************
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 import java.rmi.RemoteException; import java.util.ArrayList; import javax.ejb.CreateException; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import ma.pcard.scrashcard.session.interfaces.AlarmManager; import ma.pcard.scrashcard.session.interfaces.AlarmManagerHome; import ma.pcard.scrashcard.session.interfaces.TypeManager; import ma.pcard.scrashcard.session.interfaces.TypeManagerHome; import ma.pcard.scrashcard.struts.form.AlarmEditForm; import ma.pcard.scrashcard.struts.form.TypeEditForm; import ma.pcard.scrashcard.view.AlarmView; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; /** * MyEclipse Struts * Creation date: 04-04-2006 * * XDoclet definition: * @struts:action path="/alarmEdit" name="alarmEditForm" parameter="do" scope="request" validate="true" * @struts:action-forward name="showEdit" path="/jsp/alarmEdit.jsp" * @struts:action-forward name="showList" path="/alarmList.do" redirect="true" * @struts:action-forward name="showAdd" path="/jsp/alarmAdd.jsp" */ public class AlarmEditAction extends DispatchAction { // --------------------------------------------------------- Instance Variables // --------------------------------------------------------- Methods /** * Method editAlarm * @param mapping * @param form * @param request * @param response * @return ActionForward */ public ActionForward editAlarm( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { AlarmEditForm alarmEditForm = (AlarmEditForm) form; HttpSession session = request.getSession(); /* lalinuna.de 04.11.2004 * get id of the book from request */ Integer id = Integer.valueOf(request.getParameter("id_alarm")); //Integer id1 = Integer.valueOf(request.getParameter("id_type_alarm")); /* lalinuna.de 16.11.2004 * load the session facade and get the book by primary key */ try { InitialContext context = new InitialContext(); //holen des Home Interfaces für BookSession mit JNDI vom Appplication Server AlarmManagerHome alarmmanagerHome = (AlarmManagerHome)context.lookup(AlarmManagerHome.JNDI_NAME); AlarmManager alarmmanager = alarmmanagerHome.create(); //bestimme das Buch anhand seines Primärschlüssels und setzte es im Form Bean ArrayList tables = alarmmanager.getAllAlarm() ; AlarmView alarmView = alarmmanager.getAlarmByPrimaryKey(id) ; tables.add(alarmView); alarmEditForm.setTables(tables) ; alarmEditForm.setAlarmView(alarmmanager.getAlarmByPrimaryKey(id)); session.setAttribute("alarmView",alarmEditForm.getAlarmView()); //tables.add(String.valueOf(alarmEditForm.getId_type_alarm())); session.setAttribute("id_alarm",alarmEditForm.getId_alarm()); session.setAttribute("id_type_alarm",alarmEditForm.getId_type_alarm()); session.setAttribute("lib_alarm",alarmEditForm.getLib_alarm()); request.setAttribute("tables", tables); } catch (RemoteException e) { e.printStackTrace(); } catch (NamingException e) { e.printStackTrace(); } catch (CreateException e) { e.printStackTrace(); } return mapping.findForward("showEdit"); }
et l'attribut name alrmEditForm est bien present dans mon struts config!!!!
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200 /** * Value object for Alarm. * * @return * @xdoclet-generated at ${TODAY} * @copyright The XDoclet Team * @author XDoclet * @version ${version} */ public class AlarmValue extends java.lang.Object implements java.io.Serializable { private java.lang.Integer id_alarm; private boolean id_alarmHasBeenSet = false; private java.lang.String lib_alarm; private boolean lib_alarmHasBeenSet = false; private java.lang.Integer id_type_alarm; private boolean id_type_alarmHasBeenSet = false; private java.lang.Integer pk; public AlarmValue() { } public AlarmValue( java.lang.Integer id_alarm,java.lang.String lib_alarm,java.lang.Integer id_type_alarm ) { this.id_alarm = id_alarm; id_alarmHasBeenSet = true; this.lib_alarm = lib_alarm; lib_alarmHasBeenSet = true; this.id_type_alarm = id_type_alarm; id_type_alarmHasBeenSet = true; pk = this.getId_alarm(); } //TODO Cloneable is better than this ! public AlarmValue( AlarmValue otherValue ) { this.id_alarm = otherValue.id_alarm; id_alarmHasBeenSet = true; this.lib_alarm = otherValue.lib_alarm; lib_alarmHasBeenSet = true; this.id_type_alarm = otherValue.id_type_alarm; id_type_alarmHasBeenSet = true; pk = this.getId_alarm(); } public java.lang.Integer getPrimaryKey() { return pk; } public void setPrimaryKey( java.lang.Integer pk ) { // it's also nice to update PK object - just in case // somebody would ask for it later... this.pk = pk; setId_alarm( pk ); } public java.lang.Integer getId_alarm() { return this.id_alarm; } public void setId_alarm( java.lang.Integer id_alarm ) { this.id_alarm = id_alarm; id_alarmHasBeenSet = true; pk = id_alarm; } public boolean id_alarmHasBeenSet(){ return id_alarmHasBeenSet; } public java.lang.String getLib_alarm() { return this.lib_alarm; } public void setLib_alarm( java.lang.String lib_alarm ) { this.lib_alarm = lib_alarm; lib_alarmHasBeenSet = true; } public boolean lib_alarmHasBeenSet(){ return lib_alarmHasBeenSet; } public java.lang.Integer getId_type_alarm() { return this.id_type_alarm; } public void setId_type_alarm( java.lang.Integer id_type_alarm ) { this.id_type_alarm = id_type_alarm; id_type_alarmHasBeenSet = true; } public boolean id_type_alarmHasBeenSet(){ return id_type_alarmHasBeenSet; } public String toString() { StringBuffer str = new StringBuffer("{"); str.append("id_alarm=" + getId_alarm() + " " + "lib_alarm=" + getLib_alarm() + " " + "id_type_alarm=" + getId_type_alarm()); str.append('}'); return(str.toString()); } /** * A Value Object has an identity if the attributes making its Primary Key have all been set. An object without identity is never equal to any other object. * * @return true if this instance has an identity. */ protected boolean hasIdentity() { return id_alarmHasBeenSet; } public boolean equals(Object other) { if (this == other) return true; if ( ! hasIdentity() ) return false; if (other instanceof AlarmValue) { AlarmValue that = (AlarmValue) other; if ( ! that.hasIdentity() ) return false; boolean lEquals = true; if( this.id_alarm == null ) { lEquals = lEquals && ( that.id_alarm == null ); } else { lEquals = lEquals && this.id_alarm.equals( that.id_alarm ); } lEquals = lEquals && isIdentical(that); return lEquals; } else { return false; } } public boolean isIdentical(Object other) { if (other instanceof AlarmValue) { AlarmValue that = (AlarmValue) other; boolean lEquals = true; if( this.lib_alarm == null ) { lEquals = lEquals && ( that.lib_alarm == null ); } else { lEquals = lEquals && this.lib_alarm.equals( that.lib_alarm ); } if( this.id_type_alarm == null ) { lEquals = lEquals && ( that.id_type_alarm == null ); } else { lEquals = lEquals && this.id_type_alarm.equals( that.id_type_alarm ); } return lEquals; } else { return false; } } public int hashCode(){ int result = 17; result = 37*result + ((this.id_alarm != null) ? this.id_alarm.hashCode() : 0); result = 37*result + ((this.lib_alarm != null) ? this.lib_alarm.hashCode() : 0); result = 37*result + ((this.id_type_alarm != null) ? this.id_type_alarm.hashCode() : 0); return result; }
J'avoue que je m'y perds dans tout ce code.
Comme je n'avais pas tout le code sous les yeux, j'ai l'impression que j'ai fait fausse route.
Je pense que ce n'est pas une ArrayList de beans AlarmView qu'il faut faire mais une ArrayList de beans AlarmValue.
Pour l'instant, je n'ai pas le temps de me pencher dans le détail sur ton code mais je regarderai de plus près ce soir.
En attendant, essaie de faire une ArrayList de beans AlarmValue et vois si ça marche mieux.
Modératrice Java - Struts, Servlets/JSP, ...
On va essayer tout d'abord de régler le problème du html:select.
Dans l'Action qui initialise le formulaire :
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 public ArrayList getAllAlarm() throws javax.ejb.EJBException { try { InitialContext context = new InitialContext(); //Get the home interface with JNDI from the application server AlarmLocalHome alarmLocalHome = (AlarmLocalHome)context.lookup(AlarmLocalHome.JNDI_NAME); //get all alarms with the local home interface Collection collection = alarmLocalHome.findAll(); //define an ArrayList ArrayList arrayList = new ArrayList(); //loop over the collection for (Iterator iter = collection.iterator(); iter.hasNext();) { AlarmLocal element = (AlarmLocal) iter.next(); //define a new AlarmView object AlarmView alarmView = new AlarmView(); //set the AlarmValue in alarmView AlarmValue alarmValue=element.getAlarmValue(); //add the alarmValue object to the ArrayList arrayList.add(alarmValue); } ... return arrayList ; }
Dans l'ActionForm, pour pouvoir récupérer l'id_Type_Alarm sélecté, il faut déclarer l'attribut id_Type_Alarm et coder les méthodes getId_Type_Alarm et setId_Type_Alarm comme ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 AlarmEditForm alarmEditForm = (AlarmEditForm) form; ArrayList tables = taClasse.getAllAlarm() ; alarmEditForm.setTables(tables) ;
Et bien sûr, toujours dans l'ActionForm, il faut aussi coder le getter et le setter sur ton ArrayList tables, comme tu l'as déjà fait :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 private Integer id_Type_Alarm ; public Integer getId_Type_Alarm() { return id_Type_Alarm ; } public void setId_Type_Alarm(Integer id_Type_Alarm) { this.id_Type_Alarm=id_Type_Alarm ; }
Dans la jsp :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 private ArrayList tables; public ArrayList getTables() { return tables; } public void setTables(ArrayList tables) { this.tables = tables; }
Par contre, ce qui m'intrigue, c'est que dans ta jsp, tu affiches id_alarm et lib_alarm via des html:text sans les inclure dans une boucle.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <html:select property="id_Type_Alarm"> <html:optionsCollection property="tables" value="id_type_alarm" label="id_type_alarm"/> </html:select>
Tu as pourtant bien plusieurs records dans ta table vu la boucle codée dans la méthode getAllAlarm ?
Modératrice Java - Struts, Servlets/JSP, ...
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