|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.form; |
|
16 |
| |
|
17 |
| import java.util.Collection; |
|
18 |
| |
|
19 |
| import org.apache.tapestry.IActionListener; |
|
20 |
| import org.apache.tapestry.IForm; |
|
21 |
| import org.apache.tapestry.IMarkupWriter; |
|
22 |
| import org.apache.tapestry.IRequestCycle; |
|
23 |
| import org.apache.tapestry.listener.ListenerInvoker; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| abstract class AbstractSubmit extends AbstractFormComponent |
|
33 |
| { |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| protected abstract boolean isClicked(IRequestCycle cycle, String name); |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
18
| protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
47 |
| { |
|
48 |
18
| if (isClicked(cycle, getName()))
|
|
49 |
9
| handleClick(cycle, getForm());
|
|
50 |
| } |
|
51 |
| |
|
52 |
24
| void handleClick(final IRequestCycle cycle, IForm form)
|
|
53 |
| { |
|
54 |
24
| if (isParameterBound("selected"))
|
|
55 |
9
| setSelected(getTag());
|
|
56 |
| |
|
57 |
24
| final IActionListener listener = getListener();
|
|
58 |
24
| final IActionListener action = getAction();
|
|
59 |
| |
|
60 |
24
| if (listener == null && action == null)
|
|
61 |
9
| return;
|
|
62 |
| |
|
63 |
15
| final ListenerInvoker listenerInvoker = getListenerInvoker();
|
|
64 |
| |
|
65 |
15
| Object parameters = getParameters();
|
|
66 |
15
| if (parameters != null)
|
|
67 |
| { |
|
68 |
6
| if (parameters instanceof Collection)
|
|
69 |
| { |
|
70 |
3
| cycle.setListenerParameters(((Collection) parameters).toArray());
|
|
71 |
| } |
|
72 |
| else |
|
73 |
| { |
|
74 |
3
| cycle.setListenerParameters(new Object[]
|
|
75 |
| { parameters }); |
|
76 |
| } |
|
77 |
| } |
|
78 |
| |
|
79 |
| |
|
80 |
15
| if (listener != null)
|
|
81 |
6
| listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle);
|
|
82 |
| |
|
83 |
15
| if (action != null) {
|
|
84 |
12
| Runnable notify = new Runnable()
|
|
85 |
| { |
|
86 |
12
| public void run()
|
|
87 |
| { |
|
88 |
12
| listenerInvoker.invokeListener(action, AbstractSubmit.this, cycle);
|
|
89 |
| } |
|
90 |
| }; |
|
91 |
| |
|
92 |
12
| form.addDeferredRunnable(notify);
|
|
93 |
| } |
|
94 |
| } |
|
95 |
| |
|
96 |
| |
|
97 |
| public abstract IActionListener getListener(); |
|
98 |
| |
|
99 |
| |
|
100 |
| public abstract IActionListener getAction(); |
|
101 |
| |
|
102 |
| |
|
103 |
| public abstract Object getTag(); |
|
104 |
| |
|
105 |
| |
|
106 |
| public abstract void setSelected(Object tag); |
|
107 |
| |
|
108 |
| |
|
109 |
| public abstract boolean getDefer(); |
|
110 |
| |
|
111 |
| |
|
112 |
| public abstract Object getParameters(); |
|
113 |
| |
|
114 |
| |
|
115 |
| public abstract ListenerInvoker getListenerInvoker(); |
|
116 |
| } |