View Javadoc
1   package gboat2.base.view.components;
2   
3   import gboat2.base.bridge.util.json.JsonUtil;
4   
5   import java.io.Writer;
6   
7   import org.apache.struts2.components.Component;
8   import org.apache.struts2.views.annotations.StrutsTag;
9   import org.apache.struts2.views.annotations.StrutsTagAttribute;
10  
11  import com.fasterxml.jackson.databind.node.ObjectNode;
12  import com.opensymphony.xwork2.util.ValueStack;
13  
14  /**
15   * 设置附件上传控件需要显示的按钮
16   * @date 2014年6月25日
17   * @author <a href="mailto:[email protected]">何明旺</a>
18   * @since 3.0.0-SNAPSHOT
19   * @see Attach
20   */
21  @StrutsTag(
22          name = "attachButtons",
23          tldTagClass = "gboat2.base.view.jsp.AttachButtonsTag",
24          description = "设置附件上传控件需要显示的按钮")
25  public class AttachButtons extends Component {
26  
27      protected String browse;
28      protected String start;
29      protected String stop;
30      
31  	public AttachButtons(ValueStack stack) {
32  		super(stack);
33  	}
34  
35      @Override
36      public boolean end(Writer writer, String body) {
37          ObjectNode buttons = JsonUtil.generateMapper().createObjectNode();
38          
39          if (browse != null)
40              buttons.put("browse", (Boolean) findValue(browse, Boolean.class));
41          
42          if (start != null)
43              buttons.put("start", (Boolean) findValue(start, Boolean.class));
44          
45          if (stop != null)
46              buttons.put("stop", (Boolean) findValue(stop, Boolean.class));
47          
48          findAncestor(Attach.class).addParameter("buttons", buttons);
49          return super.end(writer, body);
50      }
51  
52      @StrutsTagAttribute(description = "是否显示“添加文件”的按钮", type = "Boolean", defaultValue = "true")
53      public void setBrowse(String browse) {
54          this.browse = browse;
55      }
56  
57      @StrutsTagAttribute(description = "是否显示“开始上传”的按钮", type = "Boolean", defaultValue = "true")
58      public void setStart(String start) {
59          this.start = start;
60      }
61  
62      @StrutsTagAttribute(description = "是否显示“停止上传”的按钮", type = "Boolean", defaultValue = "true")
63      public void setStop(String stop) {
64          this.stop = stop;
65      }
66  
67  }