View Javadoc

1   /*
2    * $Id: Anchor.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 &lt;a &gt;.<p/>
36   * <!-- END SNIPPET: javadoc -->
37   * 
38   * <p/> <b>Examples</b>
39   *
40   * <pre>
41   * <!-- START SNIPPET: example1 -->
42   * &lt;s:a id="link1" theme="ajax" href="/DoIt.action"&gt;
43   *     &lt;img border="none" src="&lt;%=request.getContextPath()%&gt;/images/delete.gif"/&gt;
44   *     &lt;s:param name="id" value="1"/&gt;
45   * &lt;/s:a&gt;
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  }