KickJava   Java API By Example, From Geeks To Geeks.

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


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 <select> element (containing <option> elements).
23  *
24  * @author Howard Lewis Ship
25  *
26  **/

27
28 public class SelectPropertySelectionRenderer
29     implements IPropertySelectionRenderer
30 {
31     /**
32      * Writes the <select> element. If the
33      * {@link PropertySelection} is {@link PropertySelection#isDisabled() disabled}
34      * then a <code>disabled</code> attribute is written into the tag
35      * (though Navigator 4 will ignore this).
36      *
37      **/

38
39     public void beginRender(
40         PropertySelection component,
41         IMarkupWriter writer,
42         IRequestCycle cycle)
43     {
44         writer.begin("select");
45         writer.attribute("name", component.getName());
46
47         if (component.isDisabled())
48             writer.attribute("disabled", "disabled");
49
50         writer.println();
51     }
52
53     /**
54      * Closes the &lt;select&gt; element.
55      *
56      **/

57
58     public void endRender(
59         PropertySelection component,
60         IMarkupWriter writer,
61         IRequestCycle cycle)
62     {
63         writer.end(); // <select>
64
}
65
66     /**
67      * Writes an &lt;option&gt; element.
68      *
69      **/

70
71     public void renderOption(
72         PropertySelection component,
73         IMarkupWriter writer,
74         IRequestCycle cycle,
75         IPropertySelectionModel model,
76         Object JavaDoc option,
77         int index,
78         boolean selected)
79     {
80         writer.beginEmpty("option");
81         writer.attribute("value", model.getValue(index));
82
83         if (selected)
84             writer.attribute("selected", "selected");
85
86         writer.print(model.getLabel(index));
87
88         writer.end();
89         
90         writer.println();
91     }
92 }
Popular Tags