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.coerce.ValueConverter; |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| public class ListenerMethodBinding extends AbstractBinding implements IActionListener |
31 |
| { |
32 |
| private final IComponent _component; |
33 |
| |
34 |
| private final String _methodName; |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| private IActionListener _listener; |
42 |
| |
43 |
45
| public ListenerMethodBinding(IComponent component, String methodName, String description,
|
44 |
| ValueConverter valueConverter, Location location) |
45 |
| { |
46 |
45
| super(description, valueConverter, location);
|
47 |
| |
48 |
45
| Defense.notNull(component, "component");
|
49 |
45
| Defense.notNull(methodName, "methodName");
|
50 |
| |
51 |
45
| _component = component;
|
52 |
45
| _methodName = methodName;
|
53 |
| } |
54 |
| |
55 |
1
| public Object getComponent()
|
56 |
| { |
57 |
1
| return _component;
|
58 |
| } |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
24
| public Object getObject()
|
65 |
| { |
66 |
24
| return this;
|
67 |
| } |
68 |
| |
69 |
39
| public void actionTriggered(IComponent component, IRequestCycle cycle)
|
70 |
| { |
71 |
39
| try
|
72 |
| { |
73 |
39
| if (_listener == null)
|
74 |
26
| _listener = _component.getListeners().getListener(_methodName);
|
75 |
| |
76 |
39
| _listener.actionTriggered(component, cycle);
|
77 |
| } |
78 |
| catch (PageRedirectException ex) |
79 |
| { |
80 |
3
| throw ex;
|
81 |
| } |
82 |
| catch (RuntimeException ex) |
83 |
| { |
84 |
1
| throw new BindingException(BindingMessages.listenerMethodFailure(
|
85 |
| _component, |
86 |
| _methodName, |
87 |
| ex), _component, getLocation(), this, ex); |
88 |
| } |
89 |
| } |
90 |
| |
91 |
1
| protected void extendDescription(StringBuffer buffer)
|
92 |
| { |
93 |
1
| buffer.append(", component=");
|
94 |
1
| buffer.append(_component.getExtendedId());
|
95 |
1
| buffer.append(", methodName=");
|
96 |
1
| buffer.append(_methodName);
|
97 |
| } |
98 |
| |
99 |
| } |