|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
FieldLabel.java | 57.1% | 66.7% | 100% | 64.1% |
|
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.valid;
|
|
16 |
|
|
17 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
18 |
import org.apache.tapestry.AbstractComponent;
|
|
19 |
import org.apache.tapestry.BindingException;
|
|
20 |
import org.apache.tapestry.IForm;
|
|
21 |
import org.apache.tapestry.IMarkupWriter;
|
|
22 |
import org.apache.tapestry.IRequestCycle;
|
|
23 |
import org.apache.tapestry.Tapestry;
|
|
24 |
import org.apache.tapestry.form.Form;
|
|
25 |
import org.apache.tapestry.form.IFormComponent;
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Used to label an {@link IFormComponent}. Because such fields
|
|
29 |
* know their displayName (user-presentable name), there's no reason
|
|
30 |
* to hard code the label in a page's HTML template (this also helps
|
|
31 |
* with localization).
|
|
32 |
*
|
|
33 |
* [<a href="../../../../../ComponentReference/FieldLabel.html">Component Reference</a>]
|
|
34 |
|
|
35 |
*
|
|
36 |
* @author Howard Lewis Lewis Ship
|
|
37 |
*
|
|
38 |
**/
|
|
39 |
|
|
40 |
public abstract class FieldLabel extends AbstractComponent |
|
41 |
{ |
|
42 |
/**
|
|
43 |
* Gets the {@link IFormComponent}
|
|
44 |
* and {@link IValidationDelegate delegate},
|
|
45 |
* then renders the label obtained from the field. Does nothing
|
|
46 |
* when rewinding.
|
|
47 |
*
|
|
48 |
**/
|
|
49 |
|
|
50 | 17 |
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
51 |
{ |
|
52 | 17 |
if (cycle.isRewinding())
|
53 | 10 |
return;
|
54 |
|
|
55 | 7 |
IFormComponent field = getField(); |
56 | 7 |
String displayName = getDisplayName(); |
57 |
|
|
58 | 7 |
if (displayName == null) |
59 |
{ |
|
60 | 7 |
if (field == null) |
61 | 0 |
throw Tapestry.createRequiredParameterException(this, "field"); |
62 |
|
|
63 | 7 |
displayName = field.getDisplayName(); |
64 |
|
|
65 | 7 |
if (displayName == null) |
66 |
{ |
|
67 | 0 |
String msg = Tapestry.format("FieldLabel.no-display-name", field.getExtendedId());
|
68 |
|
|
69 | 0 |
throw new BindingException(msg, this, null, getBinding("field"), null); |
70 |
} |
|
71 |
} |
|
72 |
|
|
73 | 7 |
IForm form = Form.get(cycle); |
74 |
|
|
75 | 7 |
if (form == null) |
76 |
{ |
|
77 | 0 |
String msg = Tapestry.getMessage("FieldLabel.must-be-contained-by-form");
|
78 |
|
|
79 | 0 |
throw new ApplicationRuntimeException(msg, this, null, null); |
80 |
} |
|
81 |
|
|
82 | 7 |
IValidationDelegate delegate = form.getDelegate(); |
83 |
|
|
84 | 7 |
if (delegate == null) |
85 |
{ |
|
86 | 0 |
String msg = |
87 |
Tapestry.format("FieldLabel.no-delegate", getExtendedId(), form.getExtendedId());
|
|
88 |
|
|
89 | 0 |
throw new ApplicationRuntimeException(msg, this, null, null); |
90 |
} |
|
91 |
|
|
92 | 7 |
delegate.writeLabelPrefix(field, writer, cycle); |
93 |
|
|
94 | 7 |
if (getRaw()) {
|
95 | 0 |
writer.printRaw(displayName); |
96 |
} else {
|
|
97 | 7 |
writer.print(displayName); |
98 |
} |
|
99 |
|
|
100 | 7 |
delegate.writeLabelSuffix(field, writer, cycle); |
101 |
} |
|
102 |
|
|
103 |
public abstract String getDisplayName();
|
|
104 |
|
|
105 |
public abstract IFormComponent getField();
|
|
106 |
|
|
107 |
public abstract boolean getRaw(); |
|
108 |
} |
|
109 |
|
|