回答編集履歴

1

サンプルコードの追加

2016/02/08 06:22

投稿

BlueMoon
BlueMoon

スコア1339

test CHANGED
@@ -1 +1,203 @@
1
1
  SessionScopedアノテーションの指定において、javax.enterprise.context.SessionScopedをインポートされていますか?javax.faces.bean.SessionScopedをインポートしているということは無いでしょうか。
2
+
3
+
4
+
5
+ 単純なサンプルですが、以下だとSessionは保持できています。
6
+
7
+ ```HTML
8
+
9
+ <html xmlns="http://www.w3.org/1999/xhtml"
10
+
11
+ xmlns:h="http://xmlns.jcp.org/jsf/html">
12
+
13
+ <h:head>
14
+
15
+ <title>JSF Page1</title>
16
+
17
+ </h:head>
18
+
19
+ <h:body>
20
+
21
+ <h:form>
22
+
23
+ <h:outputText value="#{bbPage1.atext}" />
24
+
25
+ <h:inputText value="#{bbPage1.atext}" />
26
+
27
+ <h:commandLink value="リンク" action="#{bbPage1.nextpage()}" />
28
+
29
+ </h:form>
30
+
31
+ </h:body>
32
+
33
+ </html>
34
+
35
+ ```
36
+
37
+ ```Java
38
+
39
+ package beans;
40
+
41
+
42
+
43
+ import java.io.Serializable;
44
+
45
+ import javax.annotation.PostConstruct;
46
+
47
+ import javax.enterprise.context.SessionScoped;
48
+
49
+ import javax.inject.Named;
50
+
51
+
52
+
53
+ @Named
54
+
55
+ @SessionScoped
56
+
57
+ public class BbPage1 implements Serializable{
58
+
59
+
60
+
61
+ String Atext;
62
+
63
+
64
+
65
+ @PostConstruct
66
+
67
+ public void init(){
68
+
69
+ System.out.println("in BbPage1 init");
70
+
71
+ Atext="input text";
72
+
73
+ }
74
+
75
+
76
+
77
+ public String nextpage(){
78
+
79
+ return "page2";
80
+
81
+ }
82
+
83
+
84
+
85
+ public String getAtext() {
86
+
87
+ return Atext;
88
+
89
+ }
90
+
91
+
92
+
93
+ public void setAtext(String Atext) {
94
+
95
+ this.Atext = Atext;
96
+
97
+ }
98
+
99
+ }
100
+
101
+
102
+
103
+ ```
104
+
105
+ ```HTML
106
+
107
+ <html xmlns="http://www.w3.org/1999/xhtml"
108
+
109
+ xmlns:h="http://xmlns.jcp.org/jsf/html">
110
+
111
+ <h:head>
112
+
113
+ <title>JSF Page2</title>
114
+
115
+ </h:head>
116
+
117
+ <h:body>
118
+
119
+ <h:form>
120
+
121
+ <h:outputText value="#{bbPage2.atext}" />
122
+
123
+ <h:inputText value="#{bbPage2.atext}" />
124
+
125
+ <h:commandLink value="リンク" action="#{bbPage2.nextpage()}" />
126
+
127
+ </h:form>
128
+
129
+ </h:body>
130
+
131
+ </html>
132
+
133
+ ```
134
+
135
+ ```Java
136
+
137
+ package beans;
138
+
139
+
140
+
141
+ import java.io.Serializable;
142
+
143
+ import javax.annotation.PostConstruct;
144
+
145
+ import javax.enterprise.context.SessionScoped;
146
+
147
+ import javax.inject.Named;
148
+
149
+
150
+
151
+ @Named
152
+
153
+ @SessionScoped
154
+
155
+ public class BbPage2 implements Serializable{
156
+
157
+
158
+
159
+ String Atext;
160
+
161
+
162
+
163
+ @PostConstruct
164
+
165
+ public void init(){
166
+
167
+ System.out.println("in BbPage2 init");
168
+
169
+ Atext="input text";
170
+
171
+ }
172
+
173
+
174
+
175
+ public String nextpage(){
176
+
177
+ return "page1";
178
+
179
+ }
180
+
181
+
182
+
183
+ public String getAtext() {
184
+
185
+ return Atext;
186
+
187
+ }
188
+
189
+
190
+
191
+ public void setAtext(String Atext) {
192
+
193
+ this.Atext = Atext;
194
+
195
+ }
196
+
197
+ }
198
+
199
+ ```
200
+
201
+
202
+
203
+ 環境はGlassFish4.1でIDEはNetBeans8.0.2になります。