View Javadoc
1   package gboat2.base.view.components;
2   
3   import javax.servlet.http.HttpServletRequest;
4   import javax.servlet.http.HttpServletResponse;
5   
6   import org.apache.commons.lang3.RandomStringUtils;
7   import org.apache.commons.lang3.StringUtils;
8   import org.apache.struts2.components.ClosingUIBean;
9   import org.apache.struts2.views.annotations.StrutsTag;
10  import org.apache.struts2.views.annotations.StrutsTagAttribute;
11  
12  import com.opensymphony.xwork2.util.ValueStack;
13  
14  /**
15   * <p>
16   * 创建一个可折叠的面板
17   * </p>
18   * <pre>
19   * 示例代码:
20   * &lt;g2:accordionItem title=&quot;Sed non urna&quot;&gt;
21   *   Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet,
22   *   mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna.
23   * &lt;/g2:accordionItem&gt;
24   * </pre>
25   * @see Accordion
26   * @author <a href="mailto:[email protected]">何明旺</a>
27   * @since 3.0
28   * @date 2014年6月11日
29   */
30  @StrutsTag(
31          name = "accordionItem",
32          tldTagClass = "gboat2.base.view.jsp.AccordionItemTag",
33          description = "创建一个可折叠的面板,位于 <g2:according> 标签内")
34  public class AccordionItem extends ClosingUIBean {
35      public static final String JQUERYACTION = "accordionItem";
36      public static final String TEMPLATE_CLOSE = "accordionItem-close";
37      
38      public static final String TEMPLATE = "accordionItem";
39  
40      protected String onClickTopics;
41  
42      public AccordionItem(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
43          super(stack, request, response);
44      }
45  
46      @Override
47      public String getDefaultOpenTemplate() {
48          return TEMPLATE;
49      }
50  
51      @Override
52      protected String getDefaultTemplate() {
53          return TEMPLATE_CLOSE;
54      }
55  
56      @Override
57      public void evaluateExtraParams() {
58          super.evaluateExtraParams();
59  
60          addParameter("jqueryaction", JQUERYACTION);
61  
62          if (onClickTopics != null)
63              addParameter("onClickTopics", findString(onClickTopics));
64  
65          Accordion accordion = (Accordion) findAncestor(Accordion.class);
66          if (accordion != null)
67              addParameter("header", accordion.getHeader());
68  
69          if (StringUtils.isBlank(id)) {
70              this.id = "accordionItem_" + RandomStringUtils.randomNumeric(5);
71              addParameter("id", this.id);
72          }
73      }
74  
75      @Override
76      @StrutsTagAttribute(description = "可折叠面板的标题(头部)")
77      public void setTitle(String title) {
78          super.setTitle(title);
79      }
80  
81      @StrutsTagAttribute(name = "onClickTopics", description = "A comma delimited list of topics that published when the element is clicked", type = "String", defaultValue = "")
82      public void setOnClickTopics(String onClickTopics) {
83          this.onClickTopics = onClickTopics;
84      }
85  }