2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.shale.clay.parser.builder;
22
23 import java.util.ArrayList;
24 import java.util.Iterator;
25
26 import org.apache.shale.clay.config.beans.ComponentBean;
27 import org.apache.shale.clay.config.beans.ElementBean;
28 import org.apache.shale.clay.parser.Node;
29
30 /***
31 * <p>
32 * This {@link Builder} creates a {@link org.apache.shale.clay.config.beans.ElementBean}
33 * mapped to a html select {@link org.apache.shale.clay.parser.Node} by the
34 * {@link org.apache.shale.clay.parser.builder.chain.SelectBuilderRule}. The JSF component
35 * type for a multi-select is <code>javax.faces.HtmlSelectManyMenu</code>
36 * <p>
37 */
38 public class SelectManyMenuBuilder extends Builder {
39
40 /***
41 * <p>
42 * Returns the JSF component type of
43 * <code>javax.faces.HtmlSelectManyMenu</code> that will populate the
44 * target {@link org.apache.shale.clay.config.beans.ElementBean}.
45 * </p>
46 *
47 * @param node markup node
48 * @return component type
49 */
50 protected String getComponentType(Node node) {
51 return "javax.faces.HtmlSelectManyMenu";
52 }
53
54 /***
55 * <p>
56 * Returns the <code>jsfid</code> for the target
57 * {@link org.apache.shale.clay.config.beans.ElementBean}.
58 * </p>
59 *
60 * @param node current markup node
61 * @return target jsfid
62 */
63 protected String getJsfid(Node node) {
64 return "selectManyMenu";
65 }
66
67 /***
68 * <p>
69 * Returns <code>true</code> indicating that the multi-select component
70 * can have children.
71 * </p>
72 *
73 * @return always returns <code>true</code>
74 */
75 public boolean isChildrenAllowed() {
76 return true;
77 }
78
79 /***
80 * <p>Remove any child nodes that are not "option" nodes.</p>
81 *
82 * @param node current markup node
83 * @param target bean that will be build from the node
84 * @param root the parent of the target
85 */
86 protected void encodeBegin(Node node, ElementBean target, ComponentBean root) {
87
88
89 ArrayList delList = new ArrayList();
90 Iterator ci = node.getChildren().iterator();
91 while (ci.hasNext()) {
92 Node child = (Node) ci.next();
93 if (child.getName() == null || !child.getName().equalsIgnoreCase("option")) {
94 delList.add(child);
95 }
96 }
97 for (int i = 0; i < delList.size(); i++) {
98 node.getChildren().remove(delList.get(i));
99 }
100 delList.clear();
101
102 super.encodeBegin(node, target, root);
103 }
104
105 }