1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.commons.exporter;
20
21 import javax.faces.component.ActionSource;
22 import javax.faces.component.UIComponent;
23 import javax.faces.webapp.UIComponentTag;
24 import javax.servlet.jsp.JspException;
25 import javax.servlet.jsp.tagext.Tag;
26 import javax.servlet.jsp.tagext.TagSupport;
27
28 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspTag;
29
30
31
32
33
34
35 @JSFJspTag(
36 name="mc:exporterActionListener",
37 bodyContent="JSP",
38 tagHandler="org.apache.myfaces.commons.exporter.FaceletsExporterActionListenerTag")
39 public class ExporterActionListenerTag extends TagSupport {
40
41 private static final long serialVersionUID = -1455677614701939262L;
42 private String _fileType;
43 private String _fileName;
44 private String _for;
45
46 public int doStartTag() throws JspException {
47
48
49 if (_for == null)
50 {
51 throw new JspException("for attribute not set");
52 }
53
54 if (_fileType == null)
55 {
56 throw new JspException("fileType attribute not set");
57 }
58
59 if (_fileName == null)
60 {
61 throw new JspException("fileName attribute not set");
62 }
63
64
65 UIComponentTag componentTag = UIComponentTag
66 .getParentUIComponentTag(pageContext);
67
68 if (componentTag == null)
69 {
70 throw new JspException("ExporterActionListenerTag has no UIComponentTag ancestor");
71 }
72
73 if (componentTag.getCreated())
74 {
75
76
77 UIComponent component = componentTag.getComponentInstance();
78
79 if (component instanceof ActionSource)
80 {
81 ExporterActionListener exporterActionListener = new ExporterActionListener();
82
83 exporterActionListener.setFor(_for);
84 exporterActionListener.setFileType(_fileType);
85 exporterActionListener.setFilename(_fileName);
86
87 ((ActionSource) component)
88 .addActionListener(exporterActionListener);
89 }
90 else
91 {
92 throw new JspException("Component " + component.getId()
93 + " is no ActionSource");
94 }
95 }
96
97 return Tag.SKIP_BODY;
98 }
99
100 public void release() {
101 super.release();
102 _fileType = null;
103 _fileName = null;
104 _for = null;
105 }
106
107 public String getFilename() {
108 return _fileName;
109 }
110
111
112
113
114
115
116 public void setFilename(String _filename) {
117 this._fileName = _filename;
118 }
119
120 public String getFileType() {
121 return _fileType;
122 }
123
124
125
126
127
128
129 public void setFileType(String type) {
130 _fileType = type;
131 }
132
133 public String getFor() {
134 return _for;
135 }
136
137
138
139
140
141
142 public void setFor(String _for) {
143 this._for = _for;
144 }
145
146
147 }