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 |
0 |
public abstract class ControlledCheckbox extends BaseComponent |
29 |
|
{ |
30 |
|
|
31 |
|
public abstract CheckboxGroup getGroup(); |
32 |
|
|
33 |
|
public String getCheckboxName() |
34 |
|
{ |
35 |
0 |
Checkbox checkbox = (Checkbox) getComponent("checkbox"); |
36 |
0 |
String name = checkbox.getName(); |
37 |
0 |
return name; |
38 |
|
} |
39 |
|
|
40 |
|
public IForm getForm() |
41 |
|
{ |
42 |
0 |
Checkbox checkbox = (Checkbox) getComponent("checkbox"); |
43 |
0 |
IForm form = checkbox.getForm(); |
44 |
0 |
return form; |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
52 |
|
{ |
53 |
0 |
super.renderComponent(writer, cycle); |
54 |
|
|
55 |
0 |
registerCheckbox(); |
56 |
0 |
} |
57 |
|
|
58 |
|
protected void registerCheckbox() |
59 |
|
{ |
60 |
0 |
getCheckboxGroup().registerControlledCheckbox(this); |
61 |
0 |
} |
62 |
|
|
63 |
|
public CheckboxGroup getCheckboxGroup() |
64 |
|
{ |
65 |
0 |
CheckboxGroup group = getGroup(); |
66 |
0 |
if (group == null) |
67 |
|
{ |
68 |
0 |
IRequestCycle cycle = getPage().getRequestCycle(); |
69 |
0 |
group = (CheckboxGroup) cycle |
70 |
|
.getAttribute(CheckboxGroup.CHECKBOX_GROUP_ATTRIBUTE); |
71 |
|
} |
72 |
0 |
if (group == null) |
73 |
0 |
throw new ApplicationRuntimeException( |
74 |
|
"The component " |
75 |
|
+ getExtendedId() |
76 |
|
+ " must be wrapped by a CheckboxGroup or the 'group' parameter must be set."); |
77 |
|
|
78 |
0 |
return group; |
79 |
|
} |
80 |
|
|
81 |
|
} |