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 |
12
| protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
47 |
| { |
48 |
12
| if (isClicked(cycle, getName()))
|
49 |
6
| handleClick(cycle, getForm());
|
50 |
| } |
51 |
| |
52 |
16
| void handleClick(final IRequestCycle cycle, IForm form)
|
53 |
| { |
54 |
16
| if (isParameterBound("selected"))
|
55 |
6
| setSelected(getTag());
|
56 |
| |
57 |
16
| final IActionListener listener = getListener();
|
58 |
16
| final IActionListener action = getAction();
|
59 |
| |
60 |
16
| if (listener == null && action == null)
|
61 |
6
| return;
|
62 |
| |
63 |
10
| final ListenerInvoker listenerInvoker = getListenerInvoker();
|
64 |
| |
65 |
10
| Object parameters = getParameters();
|
66 |
10
| if (parameters != null)
|
67 |
| { |
68 |
4
| if (parameters instanceof Collection)
|
69 |
| { |
70 |
2
| cycle.setListenerParameters(((Collection) parameters).toArray());
|
71 |
| } |
72 |
| else |
73 |
| { |
74 |
2
| cycle.setListenerParameters(new Object[]
|
75 |
| { parameters }); |
76 |
| } |
77 |
| } |
78 |
| |
79 |
| |
80 |
10
| if (listener != null)
|
81 |
4
| listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle);
|
82 |
| |
83 |
10
| if (action != null) {
|
84 |
8
| Runnable notify = new Runnable()
|
85 |
| { |
86 |
8
| public void run()
|
87 |
| { |
88 |
8
| listenerInvoker.invokeListener(action, AbstractSubmit.this, cycle);
|
89 |
| } |
90 |
| }; |
91 |
| |
92 |
8
| 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 |
| } |