KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > riotfamily > forms > element > Textarea


1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1
3  * The contents of this file are subject to the Mozilla Public License Version
4  * 1.1 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  * http://www.mozilla.org/MPL/
7  *
8  * Software distributed under the License is distributed on an "AS IS" basis,
9  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10  * for the specific language governing rights and limitations under the
11  * License.
12  *
13  * The Original Code is Riot.
14  *
15  * The Initial Developer of the Original Code is
16  * Neteye GmbH.
17  * Portions created by the Initial Developer are Copyright (C) 2006
18  * the Initial Developer. All Rights Reserved.
19  *
20  * Contributor(s):
21  * Felix Gnass [fgnass at neteye dot de]
22  *
23  * ***** END LICENSE BLOCK ***** */

24 package org.riotfamily.forms.element;
25
26 import java.io.PrintWriter JavaDoc;
27
28 import org.riotfamily.common.markup.Html;
29 import org.riotfamily.common.markup.TagWriter;
30 import org.riotfamily.forms.DHTMLElement;
31 import org.riotfamily.forms.resource.FormResource;
32 import org.riotfamily.forms.resource.ResourceElement;
33 import org.riotfamily.forms.resource.Resources;
34 import org.riotfamily.forms.resource.ScriptResource;
35
36
37 /**
38  * A textarea widget.
39  */

40 public class Textarea extends AbstractTextElement implements ResourceElement,
41         DHTMLElement {
42
43     private static FormResource RESOURCE = new ScriptResource(
44             "riot-js/textarea.js", "RiotTextArea", Resources.RIOT_UTIL);
45     
46     private Integer JavaDoc rows = null;
47
48     private Integer JavaDoc cols = null;
49
50     public void setCols(Integer JavaDoc cols) {
51         this.cols = cols;
52     }
53
54     public void setRows(Integer JavaDoc rows) {
55         this.rows = rows;
56     }
57
58     public void renderInternal(PrintWriter JavaDoc writer) {
59         TagWriter tag = new TagWriter(writer);
60         tag.start(Html.TEXTAREA)
61             .attribute(Html.COMMON_CLASS, getStyleClass())
62             .attribute(Html.COMMON_ID, getId())
63             .attribute(Html.INPUT_NAME, getParamName());
64         
65         if (rows != null) {
66             tag.attribute(Html.TEXTAREA_ROWS, rows.intValue());
67         }
68         if (cols != null) {
69             tag.attribute(Html.TEXTAREA_COLS, cols.intValue());
70         }
71         
72         tag.body(getText()).end();
73     }
74     
75     public FormResource getResource() {
76         return RESOURCE;
77     }
78     
79     public String JavaDoc getInitScript() {
80         if (getMaxLength() != null || rows == null) {
81             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
82             sb.append("new RiotTextArea('").append(getId()).append("')");
83             if (getMaxLength() != null) {
84                 sb.append(".setMaxLength(").append(getMaxLength()).append(')');
85             }
86             if (rows == null) {
87                 sb.append(".autoResize()");
88             }
89             sb.append(';');
90             return sb.toString();
91         }
92         return null;
93     }
94     
95 }
Popular Tags