Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jstl

 
sangeeta kapoor
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to do the following without using scripting


<% String []movies = {"One", "Two", "Three"};
pageContext.setAttribute("movieList", movies);
%>


May be for setAttribute I can use

<c:set var="movieList" scope="page" value="" />

What should I put in value and how to declare a String array without using scripting
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way through JSTL, as far as I know, to declare an array, although JSTL can happily read an array. If you don't really want to use scripting, why not to use an EL function that returns an array of Strings?

You need to define it as a public static method in a plain Java class, and then to define it in the TLD.

Then, you could have something like:

<c:set var="myArray" scope="request" value="${myFunc:getString()}" />

I haven't tried, but I guess it should work?
 
Deepa Korecherla
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Marco Tedone:
There is no way through JSTL, as far as I know, to declare an array, although JSTL can happily read an array. If you don't really want to use scripting, why not to use an EL function that returns an array of Strings?

You need to define it as a public static method in a plain Java class, and then to define it in the TLD.

Then, you could have something like:

<c:set var="myArray" scope="request" value="${myFunc:getString()}" />

I haven't tried, but I guess it should work?


----------

can't we do like this----
<c:set var="movieList" scope="page" >
One,Two,Three
</c:set>
 
Deepa Korecherla
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone...can't we do as above??
 
Nitish Bahadur
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a difference between an Array[List] of 3 elements(One, Two, Three) and a String literal containing "One, Two, Three".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic