1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.link; |
16 |
| |
17 |
| import org.apache.hivemind.ApplicationRuntimeException; |
18 |
| import org.apache.tapestry.IMarkupWriter; |
19 |
| import org.apache.tapestry.IRequestCycle; |
20 |
| import org.apache.tapestry.Tapestry; |
21 |
| import org.apache.tapestry.components.ILinkComponent; |
22 |
| import org.apache.tapestry.engine.ILink; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| public class ButtonLinkRenderer implements ILinkRenderer |
32 |
| { |
33 |
| public static final ILinkRenderer SHARED_INSTANCE = new ButtonLinkRenderer(); |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
3
| public void renderLink(IMarkupWriter writer, IRequestCycle cycle, ILinkComponent component)
|
40 |
| { |
41 |
3
| if (cycle.getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME) != null)
|
42 |
| { |
43 |
0
| String message = Tapestry.getMessage("AbstractLinkComponent.no-nesting");
|
44 |
0
| throw new ApplicationRuntimeException(message, component, null, null);
|
45 |
| } |
46 |
| |
47 |
3
| cycle.setAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME, component);
|
48 |
| |
49 |
3
| ILink link = component.getLink(cycle);
|
50 |
| |
51 |
3
| writer.begin("button");
|
52 |
3
| writer.attribute("type", "button");
|
53 |
| |
54 |
3
| if (component.isDisabled())
|
55 |
| { |
56 |
1
| writer.attribute("disabled", "disabled");
|
57 |
| } |
58 |
| |
59 |
3
| String url = link.getURL(component.getAnchor(), true);
|
60 |
3
| String target = component.getTarget();
|
61 |
3
| String onclick = (target == null) ? getScript(url) : getScript(url, target);
|
62 |
| |
63 |
3
| writer.attribute("onclick", onclick);
|
64 |
| |
65 |
3
| component.renderAdditionalAttributes(writer, cycle);
|
66 |
| |
67 |
3
| IMarkupWriter wrappedWriter = writer.getNestedWriter();
|
68 |
| |
69 |
3
| component.renderBody(wrappedWriter, cycle);
|
70 |
| |
71 |
3
| wrappedWriter.close();
|
72 |
| |
73 |
3
| writer.end();
|
74 |
| |
75 |
3
| cycle.removeAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME);
|
76 |
| } |
77 |
| |
78 |
| |
79 |
| |
80 |
| |
81 |
| |
82 |
| |
83 |
2
| protected String getScript(String url)
|
84 |
| { |
85 |
2
| return "window.location='" + url + "'";
|
86 |
| } |
87 |
| |
88 |
| |
89 |
| |
90 |
| |
91 |
| |
92 |
| |
93 |
| |
94 |
1
| protected String getScript(String url, String target)
|
95 |
| { |
96 |
1
| return "window.open('" + url + "','" + target + "')";
|
97 |
| } |
98 |
| } |