1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.talika.tarsis.taglib.form;
24
25 import java.io.IOException;
26
27 import javax.servlet.jsp.JspException;
28
29 import org.talika.tarsis.Globals;
30
31 /**
32 * Implementation of command tag.
33 *
34 * @author Jose M. Palomar
35 * @version $Revision: 130 $
36 */
37 public class CommandTag extends BaseTag {
38
39
40 /**
41 * <code>name</code> attribute. <code>name</code> attribute represents command
42 * name.
43 */
44 private String name;
45
46
47 /**
48 * Creates a new <code>CommandTag</code> object.
49 */
50 public CommandTag() {
51 }
52
53
54 /**
55 * Process the start tag for this instance.
56 *
57 * @return int SKIP_BODY.
58 * @throws JspException if somethign goes wrong during processing.
59 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
60 */
61 public int doStartTag() throws JspException {
62
63 try {
64 pageContext.getOut().print(renderInputElement());
65 }
66 catch (IOException ioe) {
67
68 }
69
70 return SKIP_BODY;
71
72 }
73
74
75 /**
76 * Renders command's input tag.
77 *
78 * @return String a string with rendered input tag.
79 */
80 public final String renderInputElement() {
81
82 StringBuffer element = new StringBuffer();
83
84 element.append("<input");
85
86 element.append(baseAttributes());
87
88 element.append(" type=\"hidden\"");
89
90 element.append(controlName());
91 element.append(controlValue());
92
93 element.append(">");
94
95 return element.toString();
96
97 }
98
99 /**
100 * Renders a string with the value of name attribute.
101 *
102 * @return String a string with the value of name attribute
103 */
104 public final String controlName() {
105
106 StringBuffer atts = new StringBuffer();
107
108 if (name != null) {
109 atts.append(" name=\"");
110 atts.append(Globals.COMMAND_NAME_PARAMETER);
111 atts.append("\"");
112 }
113
114 return atts.toString();
115 }
116
117 /**
118 * Renders a string with the value of value attribute.
119 *
120 * @return String a string with the value of value attribute
121 */
122 public final String controlValue() {
123
124 StringBuffer atts = new StringBuffer();
125
126 if (name != null) {
127 atts.append(" value=\"");
128 atts.append(name);
129 atts.append("\"");
130 }
131
132 return atts.toString();
133
134 }
135
136 /**
137 * Renders a string with values of input attributes.<br>
138 * There is no input attributes for this tag.
139 *
140 * @return String an empty string.
141 */
142 public String inputAttributes() {
143 return "";
144 }
145
146
147 /**
148 * Sets <code>name</code> attribute value.
149 *
150 * @param name String <code>name</code> attribute value.
151 */
152 public void setName(String name) {
153 this.name = name;
154 }
155
156 /**
157 * Called on a Tag handler to release state.
158 *
159 * @see javax.servlet.jsp.tagext.Tag#release()
160 */
161 public void release() {
162
163 super.release();
164
165 this.name = null;
166
167 }
168
169 }