• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Trouble accessing list by index

 
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In JSTL, what is the correct syntax to access the first item of a list? I have



but I'm getting an error ... "0" (zero) property not found ...



- Dave
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Alvarado wrote:Hi,

In JSTL, what is the correct syntax to access the first item of a list? I have



but I'm getting an error ... "0" (zero) property not found ...



- Dave



Dave, this error means it the code thinks that divwords is supposed to be a string and there is no property called "0" in an instance of String. I think it is because


should instead be:



and, why not just use the following to make it less confusing:

 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for this reply, but when I change to your suggestion



nothing is getting printed out at



producing this ...



So if I were to add other items onto the list, I wouldn't use apostraphes, just commas -- e.g. "${Overview, Details, Special Offers}?

Also, note that the forEach loop is not looping over the "divwords" list, but rather the "divNames" list, otherwise, I'd change the loop to act as you suggested. - Dave
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see now that you mean "${'Overview'}" to be a string array with one element. The code thinks this is a string.

please see this previous thread for your answer:

https://coderanch.com/t/290146/JSP/java/ForEach-array-data
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I looked at the previous thread but he declares his string array via a scriptlet and I don't want to do that -- preferring the JSTL route. So if this is not the way to declare an array of strings ...



What is? Thanks, - Dave
 
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is "Overview" and what are you trying to set divwords to?

A little clarity might go a long way to solving this issue.
 
Dave Alvarado
Ranch Hand
Posts: 436
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question on the table is how to declare a string array in JSTL. My empty searches on the Internet are starting to lead me to the conclusion it's not possible. For now, I have this ugly scriptlet ...



If someone knows how to write that as JSTL, then you are hired! Thanks, - Dave
 
Bear Bibeault
Sheriff
Posts: 67637
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There isn't a way. That would be a grave misuse of the JSTL/EL which is intended as a display mechanism. Constructing data constructs is the job of the controllers, not the views.

Is the page needs this array, why is it not being constructed in the page controller?
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic