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 |
5
| protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
47 |
| { |
48 |
5
| if (isClicked(cycle, getName()))
|
49 |
3
| handleClick(cycle, getForm());
|
50 |
| } |
51 |
| |
52 |
7
| void handleClick(final IRequestCycle cycle, IForm form)
|
53 |
| { |
54 |
7
| if (isParameterBound("selected"))
|
55 |
3
| setSelected(getTag());
|
56 |
| |
57 |
7
| final IActionListener listener = getListener();
|
58 |
| |
59 |
7
| if (listener == null)
|
60 |
3
| return;
|
61 |
| |
62 |
4
| final ListenerInvoker listenerInvoker = getListenerInvoker();
|
63 |
| |
64 |
4
| Object parameters = getParameters();
|
65 |
4
| if (parameters != null)
|
66 |
| { |
67 |
2
| if (parameters instanceof Collection)
|
68 |
| { |
69 |
1
| cycle.setListenerParameters(((Collection) parameters).toArray());
|
70 |
| } |
71 |
| else |
72 |
| { |
73 |
1
| cycle.setListenerParameters(new Object[]
|
74 |
| { parameters }); |
75 |
| } |
76 |
| } |
77 |
| |
78 |
| |
79 |
| |
80 |
4
| Runnable notify = new Runnable()
|
81 |
| { |
82 |
4
| public void run()
|
83 |
| { |
84 |
4
| listenerInvoker.invokeListener(listener, AbstractSubmit.this, cycle);
|
85 |
| } |
86 |
| }; |
87 |
| |
88 |
4
| if (getDefer())
|
89 |
3
| form.addDeferredRunnable(notify);
|
90 |
| else |
91 |
1
| notify.run();
|
92 |
| } |
93 |
| |
94 |
| |
95 |
| public abstract IActionListener getListener(); |
96 |
| |
97 |
| |
98 |
| public abstract Object getTag(); |
99 |
| |
100 |
| |
101 |
| public abstract void setSelected(Object tag); |
102 |
| |
103 |
| |
104 |
| public abstract boolean getDefer(); |
105 |
| |
106 |
| |
107 |
| public abstract Object getParameters(); |
108 |
| |
109 |
| |
110 |
| public abstract ListenerInvoker getListenerInvoker(); |
111 |
| } |