質問するログイン新規登録

回答編集履歴

1

実証したコードを記載

2015/09/24 09:15

投稿

BlueMoon
BlueMoon

スコア1339

answer CHANGED
@@ -1,5 +1,88 @@
1
- <p:dialog>内側に<h:form>のタグが必要という記事見つけました。
1
+ Primefaceajaxタグを使用したところ、ダイアログの選択結果が反映出来ました。
2
2
 
3
+ 呼び側のページコードです。
4
+ ```HTML
5
+ <h:form id="form1">
6
+ Hello from Facelets
7
+ <br />
8
+ <h:inputText id="dummyTextInput" value="#{dfView.atext}" />
9
+ <p:commandButton value="view" actionListener="#{dfView.viewCars()}" >
3
- [Primefaces layout + modal dialog のメモ](http://odashinsuke.hatenablog.com/entry/2014/04/12/150424)
10
+ <p:ajax event="dialogReturn" listener="#{dfView.handleReturn}" update="dummyTextInput" />
11
+ </p:commandButton>
12
+ </h:form>
13
+ ```
14
+ BackingBean
15
+ ```Java
16
+ import java.io.Serializable;
17
+ import javax.enterprise.context.SessionScoped;
18
+ import javax.inject.Named;
19
+ import org.primefaces.context.RequestContext;
20
+ import org.primefaces.event.SelectEvent;
21
+
22
+ @Named("dfView")
23
+ @SessionScoped
24
+ public class DFView implements Serializable{
25
+
26
+ String Atext;
27
+
28
+ public void viewCars() {
29
+ RequestContext.getCurrentInstance().openDialog("viewCars");
30
+ }
4
31
 
32
+ public void selectCarFromDialog(Car car) {
33
+ RequestContext.getCurrentInstance().closeDialog(car);
34
+ }
35
+
36
+ public void handleReturn(SelectEvent event) {
37
+ Car car = (Car) event.getObject();
38
+ Atext=car.brand;
39
+ }
40
+
41
+ public void selectCar(Car car) {
42
+ Atext=car.brand;
43
+ }
44
+
45
+
46
+ public String getAtext() {
47
+ return Atext;
48
+ }
49
+
50
+ public void setAtext(String Atext) {
51
+ this.Atext = Atext;
52
+ }
53
+
54
+ }
55
+
56
+ ```
57
+ daialogのページです。
58
+ ```HTML
59
+ <h:form>
60
+ <p:dataTable var="car" value="#{carList.cars}">
61
+ <p:column headerText="Id">
62
+ <h:outputText value="#{car.id}" />
63
+ </p:column>
64
+
65
+ <p:column headerText="Year">
66
+ <h:outputText value="#{car.year}" />
67
+ </p:column>
68
+
69
+ <p:column headerText="Brand">
70
+ <h:outputText value="#{car.brand}" />
71
+ </p:column>
72
+
73
+ <p:column headerText="Color">
74
+ <h:outputText value="#{car.color}" />
75
+ </p:column>
76
+
77
+ <p:column headerText="select">
78
+ <p:commandButton icon="ui-icon-search"
79
+ actionListener="#{dfView.selectCarFromDialog(car)}" />
80
+ </p:column>
81
+
82
+ </p:dataTable>
83
+ </h:form>
84
+ ```
85
+
5
- ご参考までに。
86
+ ご参考までに。
87
+
88
+ ※先の回答は外していたようなので、削除いたしました。