1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.component;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Iterator;
24 import javax.faces.context.FacesContext;
25 import javax.faces.convert.Converter;
26 import javax.faces.model.SelectItem;
27
28 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
29 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFJspProperty;
30
31
32
33
34
35
36
37
38
39
40
41
42 @JSFComponent(defaultRendererType = "javax.faces.Menu")
43 @JSFJspProperty(name="hideNoSelectionOption", returnType="boolean")
44 public class UISelectOne extends UIInput
45 {
46 public static final String COMPONENT_TYPE = "javax.faces.SelectOne";
47 public static final String COMPONENT_FAMILY = "javax.faces.SelectOne";
48
49 public static final String INVALID_MESSAGE_ID = "javax.faces.component.UISelectOne.INVALID";
50
51 public UISelectOne()
52 {
53 setRendererType("javax.faces.Menu");
54 }
55
56 @Override
57 public String getFamily()
58 {
59 return COMPONENT_FAMILY;
60 }
61
62
63
64
65
66
67
68 @Override
69 protected void validateValue(FacesContext context, Object value)
70 {
71 super.validateValue(context, value);
72
73 if (!isValid() || value == null)
74 {
75 return;
76 }
77
78
79
80 Converter converter = getConverter();
81
82
83 Collection<SelectItem> items = new ArrayList<SelectItem>();
84 for (Iterator<SelectItem> iter = new _SelectItemsIterator(this, context); iter.hasNext();)
85 {
86 items.add(iter.next());
87 }
88
89 if (_SelectItemsUtil.matchValue(context, this, value, items.iterator(), converter))
90 {
91 if (! this.isRequired())
92 {
93 return;
94 }
95 if (! _SelectItemsUtil.isNoSelectionOption(context, this, value,
96 items.iterator(), converter))
97 {
98 return;
99 }
100 }
101 _MessageUtils.addErrorMessage(context, this, INVALID_MESSAGE_ID,
102 new Object[] {_MessageUtils.getLabel(context, this) });
103 setValid(false);
104 }
105 }