~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to src/share/org/apache/struts/taglib/html/ButtonTag.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
ImportĀ upstreamĀ versionĀ 1.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/ButtonTag.java,v 1.18 2004/03/14 06:23:46 sraeburn Exp $
 
3
 * $Revision: 1.18 $
 
4
 * $Date: 2004/03/14 06:23:46 $
 
5
 *
 
6
 * Copyright 1999-2004 The Apache Software Foundation.
 
7
 * 
 
8
 * Licensed under the Apache License, Version 2.0 (the "License");
 
9
 * you may not use this file except in compliance with the License.
 
10
 * You may obtain a copy of the License at
 
11
 * 
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 * 
 
14
 * Unless required by applicable law or agreed to in writing, software
 
15
 * distributed under the License is distributed on an "AS IS" BASIS,
 
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
17
 * See the License for the specific language governing permissions and
 
18
 * limitations under the License.
 
19
 */
 
20
 
 
21
package org.apache.struts.taglib.html;
 
22
 
 
23
import javax.servlet.jsp.JspException;
 
24
 
 
25
import org.apache.struts.taglib.TagUtils;
 
26
 
 
27
/**
 
28
 * Renders an HTML BUTTON tag within the Struts framework.
 
29
 *
 
30
 * @version $Revision: 1.18 $ $Date: 2004/03/14 06:23:46 $
 
31
 */
 
32
public class ButtonTag extends BaseHandlerTag {
 
33
 
 
34
 
 
35
    // ----------------------------------------------------- Instance Variables
 
36
 
 
37
    /**
 
38
     * The property name of the generated button.
 
39
     */
 
40
    protected String property = null;
 
41
 
 
42
 
 
43
    /**
 
44
     * The body content of this tag (if any).
 
45
     */
 
46
    protected String text = null;
 
47
 
 
48
 
 
49
    /**
 
50
     * The value of the button label.
 
51
     */
 
52
    protected String value = null;
 
53
 
 
54
 
 
55
    // ------------------------------------------------------------- Properties
 
56
 
 
57
 
 
58
    /**
 
59
     * Return the property name.
 
60
     */
 
61
    public String getProperty() {
 
62
        return (property);
 
63
    }
 
64
 
 
65
    /**
 
66
     * Set the property name.
 
67
     *
 
68
     * @param property The property name
 
69
     */
 
70
    public void setProperty(String property) {
 
71
        this.property = property;
 
72
    }
 
73
 
 
74
 
 
75
    /**
 
76
     * Return the label value.
 
77
     */
 
78
    public String getValue() {
 
79
        return (value);
 
80
    }
 
81
 
 
82
 
 
83
    /**
 
84
     * Set the label value.
 
85
     * @param value The label value
 
86
     */
 
87
    public void setValue(String value) {
 
88
        this.value = value;
 
89
    }
 
90
 
 
91
 
 
92
    // --------------------------------------------------------- Public Methods
 
93
 
 
94
 
 
95
    /**
 
96
     * Process the start of this tag.
 
97
     * @exception JspException if a JSP exception has occurred
 
98
     */
 
99
    public int doStartTag() throws JspException {
 
100
 
 
101
        // Do nothing until doEndTag() is called
 
102
        this.text = null;
 
103
        return (EVAL_BODY_TAG);
 
104
 
 
105
    }
 
106
 
 
107
 
 
108
    /**
 
109
     * Save the associated label from the body content (if any).
 
110
     * @exception JspException if a JSP exception has occurred
 
111
     */
 
112
    public int doAfterBody() throws JspException {
 
113
 
 
114
        if (bodyContent != null) {
 
115
            String value = bodyContent.getString().trim();
 
116
            if (value.length() > 0)
 
117
                text = value;
 
118
        }
 
119
        return (SKIP_BODY);
 
120
 
 
121
    }
 
122
 
 
123
 
 
124
    /**
 
125
     * Process the end of this tag.
 
126
     * <p>
 
127
     * Support for indexed property since Struts 1.1
 
128
     * @exception JspException if a JSP exception has occurred
 
129
     */
 
130
    public int doEndTag() throws JspException {
 
131
 
 
132
        // Acquire the label value we will be generating
 
133
        String label = value;
 
134
        if ((label == null) && (text != null))
 
135
            label = text;
 
136
        if ((label == null) || (label.trim().length() < 1))
 
137
            label = "Click";
 
138
 
 
139
        // Generate an HTML element
 
140
        StringBuffer results = new StringBuffer();
 
141
        results.append("<input type=\"button\"");
 
142
        if (property != null) {
 
143
            results.append(" name=\"");
 
144
            results.append(property);
 
145
            // * @since Struts 1.1
 
146
            if( indexed )
 
147
                prepareIndex( results, null );
 
148
            results.append("\"");
 
149
        }
 
150
        if (accesskey != null) {
 
151
            results.append(" accesskey=\"");
 
152
            results.append(accesskey);
 
153
            results.append("\"");
 
154
        }
 
155
        if (tabindex != null) {
 
156
            results.append(" tabindex=\"");
 
157
            results.append(tabindex);
 
158
            results.append("\"");
 
159
        }
 
160
        results.append(" value=\"");
 
161
        results.append(label);
 
162
        results.append("\"");
 
163
        results.append(prepareEventHandlers());
 
164
        results.append(prepareStyles());
 
165
        results.append(getElementClose());
 
166
 
 
167
        // Render this element to our writer
 
168
        TagUtils.getInstance().write(pageContext, results.toString());
 
169
 
 
170
        // Evaluate the remainder of this page
 
171
        return (EVAL_PAGE);
 
172
 
 
173
    }
 
174
 
 
175
 
 
176
    /**
 
177
     * Release any acquired resources.
 
178
     */
 
179
    public void release() {
 
180
 
 
181
        super.release();
 
182
        property = null;
 
183
        text = null;
 
184
        value = null;
 
185
 
 
186
    }
 
187
 
 
188
 
 
189
}