|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.binding; |
|
16 |
| |
|
17 |
| import org.apache.hivemind.Location; |
|
18 |
| import org.apache.hivemind.util.Defense; |
|
19 |
| import org.apache.tapestry.BindingException; |
|
20 |
| import org.apache.tapestry.IActionListener; |
|
21 |
| import org.apache.tapestry.IComponent; |
|
22 |
| import org.apache.tapestry.IRequestCycle; |
|
23 |
| import org.apache.tapestry.PageRedirectException; |
|
24 |
| import org.apache.tapestry.RedirectException; |
|
25 |
| import org.apache.tapestry.coerce.ValueConverter; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public class ListenerMethodBinding extends AbstractBinding implements IActionListener |
|
32 |
| { |
|
33 |
| private final IComponent _component; |
|
34 |
| |
|
35 |
| private final String _methodName; |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| private IActionListener _listener; |
|
43 |
| |
|
44 |
108
| public ListenerMethodBinding(String description, ValueConverter valueConverter, Location location,
|
|
45 |
| IComponent component, String methodName) |
|
46 |
| { |
|
47 |
108
| super(description, valueConverter, location);
|
|
48 |
| |
|
49 |
108
| Defense.notNull(component, "component");
|
|
50 |
108
| Defense.notNull(methodName, "methodName");
|
|
51 |
| |
|
52 |
108
| _component = component;
|
|
53 |
108
| _methodName = methodName;
|
|
54 |
| } |
|
55 |
| |
|
56 |
3
| public Object getComponent()
|
|
57 |
| { |
|
58 |
3
| return _component;
|
|
59 |
| } |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
72
| public Object getObject()
|
|
66 |
| { |
|
67 |
72
| return this;
|
|
68 |
| } |
|
69 |
| |
|
70 |
120
| public void actionTriggered(IComponent component, IRequestCycle cycle)
|
|
71 |
| { |
|
72 |
120
| try
|
|
73 |
| { |
|
74 |
120
| if (_listener == null)
|
|
75 |
81
| _listener = _component.getListeners().getListener(_methodName);
|
|
76 |
| |
|
77 |
120
| _listener.actionTriggered(component, cycle);
|
|
78 |
| } |
|
79 |
| catch (PageRedirectException ex) |
|
80 |
| { |
|
81 |
9
| throw ex;
|
|
82 |
| } |
|
83 |
| catch (RedirectException ex) |
|
84 |
| { |
|
85 |
3
| throw ex;
|
|
86 |
| } |
|
87 |
| catch (RuntimeException ex) |
|
88 |
| { |
|
89 |
3
| throw new BindingException(BindingMessages.listenerMethodFailure(
|
|
90 |
| _component, |
|
91 |
| _methodName, |
|
92 |
| ex), _component, getLocation(), this, ex); |
|
93 |
| } |
|
94 |
| } |
|
95 |
| |
|
96 |
3
| protected void extendDescription(StringBuffer buffer)
|
|
97 |
| { |
|
98 |
3
| buffer.append(", component=");
|
|
99 |
3
| buffer.append(_component.getExtendedId());
|
|
100 |
3
| buffer.append(", methodName=");
|
|
101 |
3
| buffer.append(_methodName);
|
|
102 |
| } |
|
103 |
| |
|
104 |
| } |