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.Div;
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   * 创建一个进度条,详见 <a target="_blank" href="http://api.jqueryui.com/progressbar/">Progressbar Widget</a>
16   * <p>
17   * 示例代码:
18   * <pre>
19   * &lt;g2:progressbar value=&quot;40&quot; /&gt;
20   * </pre>
21   * </p>
22   * @author <a href="mailto:[email protected]">何明旺</a>
23   * @since 3.0
24   * @date 2014年6月9日
25   */
26  @StrutsTag(name = "progressbar",
27      tldTagClass = "gboat2.base.view.jsp.ProgressbarTag",
28      description = "Render an progressbar.",
29      allowDynamicAttributes = true)
30  public class Progressbar extends Div {
31      public static final String TEMPLATE = "progressbar";
32      public static final String TEMPLATE_CLOSE = "progressbar-close";
33  
34      public static final String JQUERYACTION = "progressbar";
35  
36      protected String max;
37      protected String onChangeTopics;
38      protected String onCompleteTopics;
39  
40      public Progressbar(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
41          super(stack, request, response);
42      }
43  
44      @Override
45      public String getDefaultOpenTemplate() {
46          return TEMPLATE;
47      }
48  
49      @Override
50      protected String getDefaultTemplate() {
51          return TEMPLATE_CLOSE;
52      }
53  
54      @Override
55      public void evaluateExtraParams() {
56          super.evaluateExtraParams();
57  
58          addParameter("jqueryaction", JQUERYACTION);
59          
60          if (max != null)
61              addParameter("max", findValue(max, Integer.class));
62          
63          if (onChangeTopics != null)
64              addParameter("onChangeTopics", findString(onChangeTopics));
65  
66          if (onCompleteTopics != null)
67              addParameter("onCompleteTopics", findString(onCompleteTopics));
68  
69          if (StringUtils.isBlank(id)) {
70              this.id = "progressbar_" + RandomStringUtils.randomNumeric(3);
71              addParameter("id", this.id);
72          }
73      }
74  
75      @Override
76      @StrutsTagAttribute(description = "如果设置为 true,则禁用该 progressbar(进度条)", type = "Boolean", defaultValue = "false")
77      public void setDisabled(String disabled) {
78          super.setDisabled(disabled);
79      }
80  
81      @StrutsTagAttribute(description = "progressbar(进度条)的最大值", type = "Integer", defaultValue = "100")
82      public void setMax(String max) {
83          this.max = max;
84      }
85  
86      @Override
87      @StrutsTagAttribute(required = true, description = "progressbar(进度条)的进度值", type = "Integer", defaultValue = "0")
88      public void setValue(String value) {
89          super.setValue(value);
90      }
91  
92      @StrutsTagAttribute(description = "当 progressbar(进度条) 的值改变时,发布的消息主题。多值之间使用逗号分隔")
93      public void setOnChangeTopics(String onChangeTopics) {
94          this.onChangeTopics = onChangeTopics;
95      }
96  
97      @StrutsTagAttribute(description = "当 progressbar(进度条)达到最大值时,发布的消息主题。多值之间使用逗号分隔")
98      public void setOnCompleteTopics(String onCompleteTopics) {
99          this.onCompleteTopics = onCompleteTopics;
100     }
101 }