Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an array in JSF EL?

Tags:

jsp

jsf

el

I want create an array in JSF EL. How can I do that? Is it even possible?

To illustrate what I am trying:

<rich:pickList addAllText="" addText="" removeAllText="" removeText="">
    <f:selectItems value="#{'Test', 'TestTest', 'TestTestTest'}" />
</rich:pickList>
like image 224
Sandro Avatar asked May 22 '12 14:05

Sandro


1 Answers

If you're on EL 3.0 or newer, you can construct collections directly in EL.

<f:selectItems value="#{['Test','TestTest','TestTestTest']}" />

If you're not on EL 3.0 yet, you could solve this particular case with a fn:split() trick.

<html ... xmlns:fn="http://java.sun.com/jsp/jstl/functions">
...
<f:selectItems value="#{fn:split('Test,TestTest,TestTestTest', ',')}" />

Either way, this requires a minimum of JSF 2.0 for the support of List<T> in <f:selectItems>.

like image 168
BalusC Avatar answered Oct 12 '22 00:10

BalusC