I’m developing a JSF page that contains a form with a lot of input string values. I don’t want to create a corresponding field in the bean for each input . Is it possible to use a map instead.
Here’s what i want my form input element to look like:
<h:inputText value='#{myBean.data["key"]}' /> // or something like this
And the bean contains the map as follows:
class myBean {
Map data;
...
}
Nothing special. Just a standard getter as you should always use for model properties.
A setter is not mandatory as it won’t be used anyway. EL will use map’s own
put()method for that. You only need to make sure that the map is already precreated in bean’s (post)constructor, JSF/EL won’t do that for you.