Thanks. The pageContext.setAttribute() works!
-----Original Message-----
From: Serge Knystautas [mailto:[EMAIL PROTECTED]
Sent: Tuesday, September 09, 2003 9:43 AM
To: Tag Libraries Users List
Subject: Re: Arrays in EL
Ely Eshel wrote:
> Hi!
> How can I set up an array of strings in EL, so that I can refer to each
> string as ${array[i]) with i being either a literal value or a variable?
> I want to accomplish the equivalent of the following, using an array
index
> instead of a hard-coded number:
> <%
> String[] DB_FIELDS = {"name_last", "name_init", "name_first"};
> %>
> <c:set var="db_fields_1">
> <%=DB_FIELDS[1]%>
> </c:set>
> <c:out value="${db_fields_1}"/><br>
> When trying to use the following code:
> <c:set var="db_fields">
> <%=DB_FIELDS%>
> </c:set>
> <c:out value="${db_fields[1]}"/><br>
This is not how you pass parameters from scriptlets to EL. EL typically
uses pageContext/request/session/application attributes. To make
anything but a String accessible via EL, you'll want to do
pageContext.setAttribute("db_fields", DB_FIELDS), or something like that.
By using the <c:set> tag, you are printing <%=DB_FIELDS%> and then
storing that as a page context attribute. In your example, try <c:out
value="${db_fields}" /> and you'll see what happens if you do
out.println(DB_FIELDS).
--
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]