With a Set
, it is not possible as it doesn't allow referencing items by index or key. It's however possible with a List
and a Map
by just specifying the list index and map key in the input value.
With a List
:
private List<String> list; // +getter (no setter necessary)
@PostConstruct
public void init() {
list = createAndFillItSomehow();
}
<ui:repeat value="#{bean.list}" varStatus="loop">
<h:inputText value="#{bean.list[loop.index]}" />
</ui:repeat>
With a Map
(only if your environment supports EL 2.2 or JBoss EL):
private Map<String, String> map; // +getter (no setter necessary)
@PostConstruct
public void init() {
map = createAndFillItSomehow();
}
<ui:repeat value="#{bean.map.entrySet().toArray()}" var="entry">
<h:inputText value="#{bean.map[entry.key]}" />
</ui:repeat>
Noted should be that the canonical approach is to use a List
of fullworthy javabeans. Let's assume a Javabean class named Par
with properties id
and value
which maps exactly to a par
table in DB with columns id
and value
:
private List<Par> pars; // +getter (no setter necessary)
@PostConstruct
public void init() {
pars = createAndFillItSomehow();
}
<ui:repeat value="#{bean.pars}" var="par">
<h:inputText value="#{par.value}" />
</ui:repeat>
Either way, it works as good when using <p:inputText>
, it's in no way related to PrimeFaces, it's in the context of this question merely a jQuery based JSF UI component library. Just replace h:
by p:
to turn it on.