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