I want the user to enter one or more names to the JSF’s inputText components.
So I’m thinking of a managed bean like this:
public class MyBean {
private String[] names;
public String[] getNames() {
return names;
}
public void setNames(String[] names) {
this.names = names;
}
}
But, how do I map the JSF’s inputText components to this array property?
First, you need to ensure that the array or collection is preinitialized in the bean, i.e. that it is never
null, for the simple reason because JSF won’t do that for you as it doesn’t know beforehand how many items you want.E.g. in
@PostConstruct.Then, you can either just access them by an hardcoded index
or use
<ui:repeat>with avarStatusto access them by a dynamic indexDo not use the
varattribute likeIt won’t work when you submit the form, because the immutable
Stringclass literally doesn’t have a setter for the value (the getter is basically thetoString()method implied by EL).See also: