Reputation: 149
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;
...
}
Upvotes: 0
Views: 1404
Reputation: 1108742
What should getter and setter for map operation look like if I create such a code?
Nothing special. Just a standard getter as you should always use for model properties.
public Map<String, Object> getData() {
return data;
}
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.
public MyBean() {
data = new HashMap<String, Object>();
}
Upvotes: 3