1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.contrib.form.checkboxes; |
16 |
| |
17 |
| import org.apache.hivemind.ApplicationRuntimeException; |
18 |
| import org.apache.tapestry.BaseComponent; |
19 |
| import org.apache.tapestry.IForm; |
20 |
| import org.apache.tapestry.IMarkupWriter; |
21 |
| import org.apache.tapestry.IRequestCycle; |
22 |
| import org.apache.tapestry.form.Checkbox; |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| public abstract class ControlledCheckbox extends BaseComponent |
29 |
| { |
30 |
| public abstract CheckboxGroup getGroup(); |
31 |
| |
32 |
0
| public String getCheckboxName()
|
33 |
| { |
34 |
0
| Checkbox checkbox = (Checkbox) getComponent("checkbox");
|
35 |
0
| String name = checkbox.getName();
|
36 |
0
| return name;
|
37 |
| } |
38 |
| |
39 |
0
| public IForm getForm()
|
40 |
| { |
41 |
0
| Checkbox checkbox = (Checkbox) getComponent("checkbox");
|
42 |
0
| IForm form = checkbox.getForm();
|
43 |
0
| return form;
|
44 |
| } |
45 |
| |
46 |
| |
47 |
| |
48 |
| |
49 |
0
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
50 |
| { |
51 |
0
| super.renderComponent(writer, cycle);
|
52 |
| |
53 |
0
| registerCheckbox();
|
54 |
| } |
55 |
| |
56 |
0
| protected void registerCheckbox()
|
57 |
| { |
58 |
0
| getCheckboxGroup().registerControlledCheckbox(this);
|
59 |
| } |
60 |
| |
61 |
0
| public CheckboxGroup getCheckboxGroup()
|
62 |
| { |
63 |
0
| CheckboxGroup group = getGroup();
|
64 |
0
| if (group == null) {
|
65 |
0
| IRequestCycle cycle = getPage().getRequestCycle();
|
66 |
0
| group = (CheckboxGroup) cycle.getAttribute(CheckboxGroup.CHECKBOX_GROUP_ATTRIBUTE);
|
67 |
| } |
68 |
0
| if (group == null)
|
69 |
0
| throw new ApplicationRuntimeException("The component " + getExtendedId() + " must be wrapped by a CheckboxGroup or the 'group' parameter must be set.");
|
70 |
| |
71 |
0
| return group;
|
72 |
| } |
73 |
| |
74 |
| } |