Both <f:loadBundle>
and <resource-bundle>
are different ways to load properties with difference being in their access scopes. The latter has by the way the additional benefit that the bundle is also injectable in a managed bean by @ManagedProperty("#{myProp}")
Using <resource-bundle>
in faces-config.xml creates a global resource bundle which can be accessed anywhere in your application. This is implemented through a java.util.ResourceBundle
instance.
Using <f:loadBundle>
in your view creates a view-specific resource bundle which is accessible only within that view. The tag handler implements this using an internal implementation of a Map. This is as specified in the VDL of the tag:
Load a resource bundle localized for the Locale of the current view, and expose it as a java.util.Map in the request attributes of the current request under the key specified by the value of the "var" attribute of this tag.
Now since you're trying to use the values from datatypes.properties through <f:selectItems>
, you'll get the said exception. This is because the value attribute for the tag should evaluate to a Collection or an array.
Value expression pointing at any Collection or array. The member elements may be instances of SelectItem or any Java Object.
So in order to use the global bundle instance, you first have to convert the same into a List<SelectItem>
inside your backing bean before using it.
NOTE: You can verify the above cases by setting a breakpoint in the initializeItems(Object)
method in the com.sun.faces.renderkit.SelectItemsIterator
class. This is, of course, assuming that you're using the Mojarra implementation.