KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > form > RadioPropertySelectionRenderer


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 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         writer.begin("table");
39         writer.attribute("border", 0);
40         writer.attribute("cellpadding", 0);
41         writer.attribute("cellspacing", 2);
42     }
43
44     /**
45      * Closes the <table> element.
46      *
47      **/

48
49     public void endRender(PropertySelection component, IMarkupWriter writer, IRequestCycle cycle)
50     {
51         writer.end(); // <table>
52
}
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 JavaDoc option,
66         int index,
67         boolean selected)
68     {
69         writer.begin("tr");
70         writer.begin("td");
71
72         writer.beginEmpty("input");
73         writer.attribute("type", "radio");
74         writer.attribute("name", component.getName());
75         writer.attribute("value", model.getValue(index));
76
77         if (component.isDisabled())
78             writer.attribute("disabled", "disabled");
79
80         if (selected)
81             writer.attribute("checked", "checked");
82
83         writer.end(); // <td>
84

85         writer.println();
86
87         writer.begin("td");
88         writer.print(model.getLabel(index));
89         writer.end(); // <td>
90
writer.end(); // <tr>
91

92         writer.println();
93     }
94 }
Popular Tags