1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.components;
23
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26
27 import org.apache.struts2.views.annotations.StrutsTag;
28 import org.apache.struts2.views.annotations.StrutsTagAttribute;
29
30 import com.opensymphony.xwork2.util.ValueStack;
31
32 /***
33 * <!-- START SNIPPET: javadoc -->
34 *
35 * A tag that creates a HTML <a >.<p/>
36 * <!-- END SNIPPET: javadoc -->
37 *
38 * <p/> <b>Examples</b>
39 *
40 * <pre>
41 * <!-- START SNIPPET: example1 -->
42 * <s:a id="link1" theme="ajax" href="/DoIt.action">
43 * <img border="none" src="<%=request.getContextPath()%>/images/delete.gif"/>
44 * <s:param name="id" value="1"/>
45 * </s:a>
46 * <!-- END SNIPPET: example1 -->
47 * </pre>
48 *
49 */
50 @StrutsTag(
51 name="a",
52 tldTagClass="org.apache.struts2.views.jsp.ui.AnchorTag",
53 description="Render a HTML href element that when clicked can optionally call a URL via remote XMLHttpRequest and updates its targets",
54 allowDynamicAttributes=true)
55 public class Anchor extends ClosingUIBean {
56 public static final String OPEN_TEMPLATE = "a";
57 public static final String TEMPLATE = "a-close";
58 public static final String COMPONENT_NAME = Anchor.class.getName();
59
60 protected String href;
61
62 public Anchor(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
63 super(stack, request, response);
64 }
65
66 public String getDefaultOpenTemplate() {
67 return OPEN_TEMPLATE;
68 }
69
70 protected String getDefaultTemplate() {
71 return TEMPLATE;
72 }
73
74 public void evaluateExtraParams() {
75 super.evaluateExtraParams();
76
77 if (href != null)
78 addParameter("href", ensureAttributeSafelyNotEscaped(findString(href)));
79 }
80
81 @StrutsTagAttribute(description="The URL.")
82 public void setHref(String href) {
83 this.href = href;
84 }
85 }