KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > appfuse > webapp > tapestry > CheckBoxMultiplePropertySelectionRenderer


1 package org.appfuse.webapp.tapestry;
2
3 import org.apache.tapestry.IMarkupWriter;
4 import org.apache.tapestry.IRequestCycle;
5 import org.apache.tapestry.contrib.form.IMultiplePropertySelectionRenderer;
6 import org.apache.tapestry.contrib.form.MultiplePropertySelection;
7 import org.apache.tapestry.form.IPropertySelectionModel;
8
9 /**
10  * Implementation of {@link IMultiplePropertySelectionRenderer} that
11  * produces checkbox (<input type=checkbox>) elements with ids
12  * on the labels.
13  *
14  * @author Matt Raible
15  *
16  **/

17 public class CheckBoxMultiplePropertySelectionRenderer
18     implements IMultiplePropertySelectionRenderer {
19     /**
20      * Writes the <table> element.
21      *
22      **/

23     public void beginRender(MultiplePropertySelection component,
24                             IMarkupWriter writer, IRequestCycle cycle) {
25     }
26
27     /**
28      * Closes the <table> element.
29      *
30      **/

31     public void endRender(MultiplePropertySelection component,
32                           IMarkupWriter writer, IRequestCycle cycle) {
33     }
34
35     public void renderOption(MultiplePropertySelection component,
36                              IMarkupWriter writer, IRequestCycle cycle,
37                              IPropertySelectionModel model, Object JavaDoc option,
38                              int index, boolean selected) {
39         writer.begin("input");
40         writer.attribute("type", "checkbox");
41         writer.attribute("name", component.getName());
42
43         String JavaDoc id = component.getName() + "." + model.getValue(index);
44         writer.attribute("id", id);
45         writer.attribute("value", model.getValue(index));
46
47         if (component.isDisabled()) {
48             writer.attribute("disabled", "disabled");
49         }
50
51         if (selected) {
52             writer.attribute("checked", "checked");
53         }
54
55         writer.end();
56
57         writer.println();
58
59         //writer.printRaw(" ");
60
writer.begin("label");
61         writer.attribute("for", id);
62         writer.print(model.getLabel(index));
63         writer.end(); // <label>
64

65         //writer.printRaw("&nbsp;");
66

67         writer.println();
68     }
69 }
70
Popular Tags