How to display ArrayList elements by index in an EL expression on a JSF page

I want to display java arraylist in a JSF page. I created an arraylist from a database. Now I want to display the list on the JSF page by calling the index of the list items by index number. Is it possible to pass the parameter to the bean method from the EL expression on the JSF page and display it?

+5
source share
1 answer

You can access a list item at a specific index using text binding [].

@ManagedBean
@RequestScoped
public class Bean {

    private List<String> list;

    @PostConstruct
    public void init() {
        list = Arrays.asList("one", "two", "three");
    }

    public List<String> getList() {
        return list;
    }

}
#{bean.list[0]}
<br />
#{bean.list[1]}
<br />
#{bean.list[2]}

Regarding parameter passing, perhaps this is possible. EL 2.2 (or JBoss EL when you're still on EL 2.1) supports calling bean methods with arguments.

#{bean.doSomething(foo, bar)}

See also:


, , , , , <ui:repeat> <h:dataTable>, . .

<ui:repeat value="#{bean.list}" var="item">
    #{item}<br/>
</ui:repeat>

<h:dataTable value="#{bean.list}" var="item">
    <h:column>#{item}</h:column>
</h:dataTable>

. :

+25

All Articles