質問編集履歴

2

変更しました

2015/12/26 06:59

投稿

RI_KU
RI_KU

スコア24

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,10 @@
1
+ ```
2
+
3
+ /*sidebar.xhtml*/
4
+
5
+ <h:form id="sort_form">
6
+
1
- <p class="side-title"><b></b></p>
7
+ <p class="side-title"><b></b></p>
2
8
 
3
9
  <select name="sort" onchange="dropsort()">
4
10
 
@@ -14,14 +20,320 @@
14
20
 
15
21
  </select>
16
22
 
17
- ----------------------------------------------------------------------------------
18
-
19
- プロジェクト起動時、onclick属性のついているリンクをクリックしてないのに
20
-
21
- onclickイベントが発動してしまいます。
22
-
23
-
24
-
25
- クリックしたときだけイベントを発動できる方法はあるのでしょうか、また根本的にコードが間違っているのでしょうか。
26
-
27
- お願いいたします。
23
+ </h:form>
24
+
25
+ ---------------------------------------------------------------------------------
26
+
27
+ /*igishi.js*/
28
+
29
+ //<!-- コンボボックスの値をURLに置換するjavaScript -->
30
+
31
+ function dropsort() {
32
+
33
+ var browser = document.sort_form.sort.value;
34
+
35
+ location.href = browser;
36
+
37
+ }
38
+
39
+ ---------------------------------------------------------------------------------
40
+
41
+
42
+
43
+ /*IiBean.java*/
44
+
45
+ @Named(value = "iB")
46
+
47
+ @Dependent
48
+
49
+ public class IiBean {
50
+
51
+
52
+
53
+ /*変数の宣言と対応するGetter,Setterを記述する*/
54
+
55
+ static Integer ii_nendo_id=0;
56
+
57
+ static String ii_mondai_id="";
58
+
59
+ private String mondaibun;
60
+
61
+ private String mg1;
62
+
63
+ private String mg2;
64
+
65
+ private String mg3;
66
+
67
+ private String mg4;
68
+
69
+ private String mg5;
70
+
71
+
72
+
73
+ public Integer getIi_nendo_id() {
74
+
75
+ return ii_nendo_id;
76
+
77
+ }
78
+
79
+
80
+
81
+ public void setIi_nendo_id(Integer ii_nendo_id) {
82
+
83
+ IiBean.ii_nendo_id = ii_nendo_id;
84
+
85
+ }
86
+
87
+
88
+
89
+ public String getIi_mondai_id() {
90
+
91
+ return ii_mondai_id;
92
+
93
+ }
94
+
95
+
96
+
97
+ public void setIi_mondai_id(String ii_mondai_id) {
98
+
99
+ IiBean.ii_mondai_id = ii_mondai_id;
100
+
101
+ }
102
+
103
+
104
+
105
+ public String getMondaibun() {
106
+
107
+ return mondaibun;
108
+
109
+ }
110
+
111
+
112
+
113
+ public void setMondaibun(String mondaibun) {
114
+
115
+ this.mondaibun = mondaibun;
116
+
117
+ }
118
+
119
+
120
+
121
+ public String getMg1() {
122
+
123
+ return mg1;
124
+
125
+ }
126
+
127
+
128
+
129
+ public void setMg1(String mg1) {
130
+
131
+ this.mg1 = mg1;
132
+
133
+ }
134
+
135
+
136
+
137
+ public String getMg2() {
138
+
139
+ return mg2;
140
+
141
+ }
142
+
143
+
144
+
145
+ public void setMg2(String mg2) {
146
+
147
+ this.mg2 = mg2;
148
+
149
+ }
150
+
151
+
152
+
153
+ public String getMg3() {
154
+
155
+ return mg3;
156
+
157
+ }
158
+
159
+
160
+
161
+ public void setMg3(String mg3) {
162
+
163
+ this.mg3 = mg3;
164
+
165
+ }
166
+
167
+
168
+
169
+ public String getMg4() {
170
+
171
+ return mg4;
172
+
173
+ }
174
+
175
+
176
+
177
+ public void setMg4(String mg4) {
178
+
179
+ this.mg4 = mg4;
180
+
181
+ }
182
+
183
+
184
+
185
+ public String getMg5() {
186
+
187
+ return mg5;
188
+
189
+ }
190
+
191
+
192
+
193
+ public void setMg5(String mg5) {
194
+
195
+ this.mg5 = mg5;
196
+
197
+ }
198
+
199
+ /*変数の宣言とGetter,Setterの記述ここまで*/
200
+
201
+
202
+
203
+ public IiBean() {
204
+
205
+ /*MySQL(データベース:「mie」)に接続する処理*/
206
+
207
+ ResultSet rs=null;
208
+
209
+ Connection con = null;
210
+
211
+ PreparedStatement ps = null;
212
+
213
+ try {
214
+
215
+ Class.forName("com.mysql.jdbc.Driver");
216
+
217
+
218
+
219
+ con =DriverManager.getConnection("jdbc:mysql://localhost/mie","root","mysql");
220
+
221
+ /*MySQLに接続する処理ここまで*/
222
+
223
+
224
+
225
+ String sql="";
226
+
227
+ if (cntupBean.countup < 10 ) {
228
+
229
+ /*ここから変数「sql」にsql文を格納するコードを記述する*/
230
+
231
+ sql = "select mondaibun,mondaigun1,mondaigun2,mondaigun3,mondaigun4,mondaigun5 from kakomondai "
232
+
233
+ + "where nendo_id="+IiBean.ii_nendo_id+" and kamoku_id=1 and mondai_id='"+IiBean.ii_mondai_id+"0"+cntupBean.countup+"'";
234
+
235
+ /*sql格納ここまで*/
236
+
237
+ } else if(cntupBean.countup <51) {
238
+
239
+ sql = "select mondaibun,mondaigun1,mondaigun2,mondaigun3,mondaigun4,mondaigun5 from kakomondai "
240
+
241
+ + "where nendo_id="+IiBean.ii_nendo_id+" and kamoku_id=1 and mondai_id='"+IiBean.ii_mondai_id+""+cntupBean.countup+"'";
242
+
243
+ }
244
+
245
+
246
+
247
+ //ステートメントオブジェクトを生成
248
+
249
+ ps = con.prepareStatement(sql);
250
+
251
+
252
+
253
+ //クエリを実行して結果セットを取得
254
+
255
+ rs = ps.executeQuery();
256
+
257
+
258
+
259
+ //mondaiデータ取得
260
+
261
+ while(rs.next()){
262
+
263
+ this.mondaibun = rs.getString("mondaibun");
264
+
265
+ this.mg1 = rs.getString("mondaigun1");
266
+
267
+ this.mg2 = rs.getString("mondaigun2");
268
+
269
+ this.mg3 = rs.getString("mondaigun3");
270
+
271
+ this.mg4 = rs.getString("mondaigun4");
272
+
273
+ this.mg5 = rs.getString("mondaigun5");
274
+
275
+ System.out.println("●"+this.mondaibun);
276
+
277
+ System.out.println("●"+this.mg1);
278
+
279
+ System.out.println("●"+this.mg2);
280
+
281
+ System.out.println("●"+this.mg3);
282
+
283
+ System.out.println("●"+this.mg4);
284
+
285
+ System.out.println("●"+this.mg5);
286
+
287
+ }
288
+
289
+ } catch (SQLException ex) {
290
+
291
+ Logger.getLogger(IiBean.class.getName()).log(Level.SEVERE, null, ex);
292
+
293
+ } catch (ClassNotFoundException ex) {
294
+
295
+ Logger.getLogger(IiBean.class.getName()).log(Level.SEVERE, null, ex);
296
+
297
+ }finally{
298
+
299
+ try {
300
+
301
+ //close処理
302
+
303
+ if(ps != null) {
304
+
305
+ ps.close();
306
+
307
+ }
308
+
309
+ //close処理
310
+
311
+ if(con != null) {
312
+
313
+ con.close();
314
+
315
+ }
316
+
317
+ } catch (SQLException e) {
318
+
319
+ e.printStackTrace();
320
+
321
+ }
322
+
323
+ }
324
+
325
+ }
326
+
327
+ }
328
+
329
+ ```
330
+
331
+ sidebarのselect optionの値をクリックしたとき、ページ遷移とともにバッキングビーンに値を渡したいと考えています。
332
+
333
+ ですが、最後のonclickしかイベントが発火していない状況です。
334
+
335
+ 他に案、またなにか代替案はあるでしょうか、
336
+
337
+
338
+
339
+ *glassfish4.1です。

1

2015/12/26 06:59

投稿

RI_KU
RI_KU

スコア24

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- <p class="side-title"><b>医療情報技師 過去問</b></p>
1
+ <p class="side-title"><b></b></p>
2
2
 
3
3
  <select name="sort" onchange="dropsort()">
4
4