|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.form; |
|
16 |
| |
|
17 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
18 |
| import org.apache.tapestry.AbstractComponent; |
|
19 |
| import org.apache.tapestry.IMarkupWriter; |
|
20 |
| import org.apache.tapestry.IRequestCycle; |
|
21 |
| import org.apache.tapestry.Tapestry; |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| public abstract class Option extends AbstractComponent |
|
32 |
| { |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
93
| protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
42 |
| { |
|
43 |
93
| Select select = Select.get(cycle);
|
|
44 |
93
| if (select == null)
|
|
45 |
3
| throw new ApplicationRuntimeException(Tapestry
|
|
46 |
| .getMessage("Option.must-be-contained-by-select"), this, null, null); |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
90
| boolean rewinding = select.isRewinding();
|
|
52 |
| |
|
53 |
90
| String value = select.getNextOptionId();
|
|
54 |
| |
|
55 |
90
| if (rewinding)
|
|
56 |
| { |
|
57 |
33
| if (!select.isDisabled())
|
|
58 |
33
| setSelected(select.isSelected(value));
|
|
59 |
| |
|
60 |
33
| renderBody(writer, cycle);
|
|
61 |
| } |
|
62 |
| else |
|
63 |
| { |
|
64 |
57
| writer.begin("option");
|
|
65 |
| |
|
66 |
57
| writer.attribute("value", value);
|
|
67 |
| |
|
68 |
57
| if (isSelected())
|
|
69 |
12
| writer.attribute("selected", "selected");
|
|
70 |
| |
|
71 |
57
| renderInformalParameters(writer, cycle);
|
|
72 |
| |
|
73 |
57
| String label = getLabel();
|
|
74 |
| |
|
75 |
57
| if (label != null)
|
|
76 |
42
| writer.print(label);
|
|
77 |
| |
|
78 |
57
| renderBody(writer, cycle);
|
|
79 |
| |
|
80 |
57
| writer.end();
|
|
81 |
| } |
|
82 |
| |
|
83 |
| } |
|
84 |
| |
|
85 |
| public abstract String getLabel(); |
|
86 |
| |
|
87 |
| public abstract boolean isSelected(); |
|
88 |
| |
|
89 |
| public abstract void setSelected(boolean selected); |
|
90 |
| } |