Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
TextArea |
|
| 1.4285714285714286;1.429 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.form; |
|
16 | ||
17 | import org.apache.tapestry.IMarkupWriter; |
|
18 | import org.apache.tapestry.IRequestCycle; |
|
19 | import org.apache.tapestry.valid.ValidatorException; |
|
20 | ||
21 | /** |
|
22 | * Implements a component that manages an HTML <textarea> form element. [<a |
|
23 | * href="../../../../../ComponentReference/TextArea.html">Component Reference</a>] |
|
24 | * <p> |
|
25 | * As of 4.0, this component can be configurably translated and validated. |
|
26 | * |
|
27 | * @author Howard Lewis Ship |
|
28 | * @author Paul Ferraro |
|
29 | */ |
|
30 | 10 | public abstract class TextArea extends AbstractFormComponent implements TranslatedField { |
31 | ||
32 | public abstract Object getValue(); |
|
33 | ||
34 | public abstract void setValue(Object value); |
|
35 | ||
36 | /** |
|
37 | * @see org.apache.tapestry.form.AbstractFormComponent#renderFormComponent(org.apache.tapestry.IMarkupWriter, |
|
38 | * org.apache.tapestry.IRequestCycle) |
|
39 | */ |
|
40 | protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) |
|
41 | { |
|
42 | 4 | String value = getTranslatedFieldSupport().format(this, getValue()); |
43 | ||
44 | 4 | renderDelegatePrefix(writer, cycle); |
45 | ||
46 | 4 | writer.begin("textarea"); |
47 | ||
48 | 4 | writer.attribute("name", getName()); |
49 | ||
50 | 4 | if (isDisabled()) |
51 | 1 | writer.attribute("disabled", "disabled"); |
52 | ||
53 | 4 | renderIdAttribute(writer, cycle); |
54 | ||
55 | 4 | renderDelegateAttributes(writer, cycle); |
56 | ||
57 | 4 | getTranslatedFieldSupport().renderContributions(this, writer, cycle); |
58 | 4 | getValidatableFieldSupport().renderContributions(this, writer, cycle); |
59 | ||
60 | 4 | renderInformalParameters(writer, cycle); |
61 | ||
62 | 4 | if (value != null) |
63 | 4 | writer.print(value); |
64 | ||
65 | 4 | writer.end(); |
66 | ||
67 | 4 | renderDelegateSuffix(writer, cycle); |
68 | 4 | } |
69 | ||
70 | /** |
|
71 | * @see org.apache.tapestry.form.AbstractFormComponent#rewindFormComponent(org.apache.tapestry.IMarkupWriter, |
|
72 | * org.apache.tapestry.IRequestCycle) |
|
73 | */ |
|
74 | protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle) |
|
75 | { |
|
76 | 3 | String value = cycle.getParameter(getName()); |
77 | ||
78 | try |
|
79 | { |
|
80 | 3 | String text = (String) getTranslatedFieldSupport().parse(this, value); |
81 | ||
82 | 2 | getValidatableFieldSupport().validate(this, writer, cycle, text); |
83 | ||
84 | 1 | setValue(text); |
85 | } |
|
86 | 2 | catch (ValidatorException e) |
87 | { |
|
88 | 2 | getForm().getDelegate().record(e); |
89 | 1 | } |
90 | 3 | } |
91 | ||
92 | /** |
|
93 | * Injected. |
|
94 | */ |
|
95 | public abstract ValidatableFieldSupport getValidatableFieldSupport(); |
|
96 | ||
97 | /** |
|
98 | * Injected. |
|
99 | */ |
|
100 | public abstract TranslatedFieldSupport getTranslatedFieldSupport(); |
|
101 | ||
102 | /** |
|
103 | * @see org.apache.tapestry.form.AbstractFormComponent#isRequired() |
|
104 | */ |
|
105 | public boolean isRequired() |
|
106 | { |
|
107 | 0 | return getValidatableFieldSupport().isRequired(this); |
108 | } |
|
109 | } |