Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
Select |
|
| 2.4;2.4 |
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.wml; |
|
16 | ||
17 | import org.apache.hivemind.ApplicationRuntimeException; |
|
18 | import org.apache.hivemind.HiveMind; |
|
19 | import org.apache.tapestry.AbstractComponent; |
|
20 | import org.apache.tapestry.IMarkupWriter; |
|
21 | import org.apache.tapestry.IRequestCycle; |
|
22 | import org.apache.tapestry.Tapestry; |
|
23 | ||
24 | /** |
|
25 | * The Select element lets users pick from a list of options. Each option is specified by an Option |
|
26 | * element. Each Option element may have one line of formatted text (which may be wrapped or |
|
27 | * truncated by the user agent if too long). Unless multiple selections are required it is generally |
|
28 | * easier to use the {@link PropertySelection}component. |
|
29 | * |
|
30 | * @author David Solis |
|
31 | * @since 3.0 |
|
32 | */ |
|
33 | 0 | public abstract class Select extends AbstractComponent |
34 | { |
|
35 | /** |
|
36 | * Used by the <code>Select</code> to record itself as a {@link IRequestCycle}attribute, so |
|
37 | * that the {@link Option}components it wraps can have access to it. |
|
38 | */ |
|
39 | ||
40 | private static final String ATTRIBUTE_NAME = "org.apache.tapestry.active.Select"; |
|
41 | ||
42 | /** |
|
43 | * @see org.apache.tapestry.AbstractComponent#renderComponent(IMarkupWriter, IRequestCycle) |
|
44 | */ |
|
45 | ||
46 | protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) |
|
47 | { |
|
48 | 0 | if (cycle.getAttribute(ATTRIBUTE_NAME) != null) |
49 | 0 | throw new ApplicationRuntimeException(Tapestry.getMessage("Select.may-not-nest"), this, |
50 | null, null); |
|
51 | ||
52 | 0 | cycle.setAttribute(ATTRIBUTE_NAME, this); |
53 | ||
54 | 0 | boolean render = !cycle.isRewinding(); |
55 | ||
56 | 0 | if (render) |
57 | { |
|
58 | 0 | writer.begin("select"); |
59 | ||
60 | 0 | writer.attribute("name", getName()); |
61 | ||
62 | 0 | String value = getValue(); |
63 | 0 | if (HiveMind.isNonBlank(value)) |
64 | 0 | writer.attribute("value", value); |
65 | ||
66 | 0 | String title = getTitle(); |
67 | 0 | if (HiveMind.isNonBlank(title)) |
68 | 0 | writer.attribute("title", title); |
69 | ||
70 | 0 | boolean multiple = isMultiple(); |
71 | 0 | if (multiple) |
72 | 0 | writer.attribute("multiple", multiple); |
73 | ||
74 | 0 | renderInformalParameters(writer, cycle); |
75 | } |
|
76 | ||
77 | 0 | renderBody(writer, cycle); |
78 | ||
79 | 0 | if (render) |
80 | { |
|
81 | 0 | writer.end(); |
82 | } |
|
83 | ||
84 | 0 | cycle.removeAttribute(ATTRIBUTE_NAME); |
85 | 0 | } |
86 | ||
87 | public abstract boolean isMultiple(); |
|
88 | ||
89 | public abstract String getName(); |
|
90 | ||
91 | public abstract String getValue(); |
|
92 | ||
93 | public abstract String getTitle(); |
|
94 | } |