1 package net.sf.tacos.components;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.apache.tapestry.AbstractComponent;
7 import org.apache.tapestry.IActionListener;
8 import org.apache.tapestry.IDirect;
9 import org.apache.tapestry.IMarkupWriter;
10 import org.apache.tapestry.IRequestCycle;
11 import org.apache.tapestry.IScript;
12 import org.apache.tapestry.Tapestry;
13 import org.apache.tapestry.TapestryUtils;
14 import org.apache.tapestry.engine.DirectServiceParameter;
15 import org.apache.tapestry.engine.IEngineService;
16 import org.apache.tapestry.engine.ILink;
17 import org.apache.tapestry.listener.ListenerInvoker;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 public abstract class ClientLink extends AbstractComponent implements IDirect{
40
41
42
43 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
44 renderBody(writer, cycle);
45
46 if (!cycle.isRewinding()) {
47 Map params = new HashMap();
48 params.put("url", getLink().getURL());
49 params.put("function", getFunction());
50 getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), params);
51 }
52 }
53
54
55
56
57 public void trigger(IRequestCycle cycle) {
58 IActionListener listener = getListener();
59 if (listener == null)
60 throw Tapestry.createRequiredParameterException(this, "listener");
61
62 getListenerInvoker().invokeListener(listener, this, cycle);
63 }
64
65
66 private ILink getLink(){
67 DirectServiceParameter dsp = new DirectServiceParameter(this);
68 return getEngine().getLink(isStateful(), dsp);
69 }
70
71
72 public abstract IActionListener getListener();
73
74 public abstract String getFunction();
75
76
77 public abstract IScript getScript();
78
79 public abstract ListenerInvoker getListenerInvoker();
80
81 public abstract IEngineService getEngine();
82 }