Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
RadioPropertySelectionRenderer |
|
| 1.6666666666666667;1.667 |
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 | ||
20 | /** |
|
21 | * Implementation of {@link IPropertySelectionRenderer} that |
|
22 | * produces a table of radio (<input type=radio>) elements. |
|
23 | * |
|
24 | * @author Howard Lewis Ship |
|
25 | * |
|
26 | **/ |
|
27 | ||
28 | 0 | public class RadioPropertySelectionRenderer implements IPropertySelectionRenderer |
29 | { |
|
30 | ||
31 | /** |
|
32 | * Writes the <table> element. |
|
33 | * |
|
34 | **/ |
|
35 | ||
36 | public void beginRender(PropertySelection component, IMarkupWriter writer, IRequestCycle cycle) |
|
37 | { |
|
38 | 0 | writer.begin("table"); |
39 | 0 | writer.attribute("border", 0); |
40 | 0 | writer.attribute("cellpadding", 0); |
41 | 0 | writer.attribute("cellspacing", 2); |
42 | 0 | } |
43 | ||
44 | /** |
|
45 | * Closes the <table> element. |
|
46 | * |
|
47 | **/ |
|
48 | ||
49 | public void endRender(PropertySelection component, IMarkupWriter writer, IRequestCycle cycle) |
|
50 | { |
|
51 | 0 | writer.end(); // <table> |
52 | 0 | } |
53 | ||
54 | /** |
|
55 | * Writes a row of the table. The table contains two cells; the first is the radio |
|
56 | * button, the second is the label for the radio button. |
|
57 | * |
|
58 | **/ |
|
59 | ||
60 | public void renderOption( |
|
61 | PropertySelection component, |
|
62 | IMarkupWriter writer, |
|
63 | IRequestCycle cycle, |
|
64 | IPropertySelectionModel model, |
|
65 | Object option, |
|
66 | int index, |
|
67 | boolean selected) |
|
68 | { |
|
69 | 0 | writer.begin("tr"); |
70 | 0 | writer.begin("td"); |
71 | ||
72 | 0 | writer.beginEmpty("input"); |
73 | 0 | writer.attribute("type", "radio"); |
74 | 0 | writer.attribute("name", component.getName()); |
75 | 0 | writer.attribute("value", model.getValue(index)); |
76 | ||
77 | 0 | if (component.isDisabled()) |
78 | 0 | writer.attribute("disabled", "disabled"); |
79 | ||
80 | 0 | if (selected) |
81 | 0 | writer.attribute("checked", "checked"); |
82 | ||
83 | 0 | writer.end(); // <td> |
84 | ||
85 | 0 | writer.println(); |
86 | ||
87 | 0 | writer.begin("td"); |
88 | 0 | writer.print(model.getLabel(index)); |
89 | 0 | writer.end(); // <td> |
90 | 0 | writer.end(); // <tr> |
91 | ||
92 | 0 | writer.println(); |
93 | 0 | } |
94 | } |