my dog learned polymorphism*
The moose likes JSP and the fly likes EL: using variable within an array-variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "EL: using variable within an array-variable" Watch "EL: using variable within an array-variable" New topic
Author

EL: using variable within an array-variable

Christian Oszczynski
Greenhorn

Joined: Jul 28, 2011
Posts: 2
Hi folks,

I'm quite new to the whole jstl things, so please don't be too harsh on me, when I'm maybe posting something self-evident OR something nonsensical.

My problem is as follows:

I've got a forEach loop which looks like this:



this works fine for me when using static values within the array-dimensions, for example like in the following line



what i would like to do now, is to have one of the dimension values set by a variable, something like



Unfortunately this does not work, therefore my question is, whether this possible at all or not. I didn't think that this would be such a big problem, but I have been searching for quite a long time in vain to solve this problem. Or maybe I still don't have understood the syntax of JSTL the right way, then please excuse me for bothering you.

A little hint would be much appreciated.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60761
    
  65

A few things:
  • List" is a really bad name for a scoped variable. Firstly, it's too generic. Secondly, scoped variable naming should follow the convention for Java variables, and start with a lowercase character.
  • ${} is not a "fetch" operator. It surrounds the entire EL expression, not just variables whose values are to be referenced. Therefore, they are never nested.

  • In other words:<c:if test="${current.ValueList[myValue][2]>='1.0'}">

    And, this is actually an EL, not a JSTL question.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Christian Oszczynski
    Greenhorn

    Joined: Jul 28, 2011
    Posts: 2
    hi bear,

    thank you very much, your solution worked out for me. regarding the "List"-naming, I am aware of that, I removed parts of my original code, so that only the semantic sense of the code remained. That is also why one variable started with an uppercase character, just wanted to post quickly, unfortunately without checking the code, sorry for that and for any further inconvenience.

    greetings
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60761
        
      65

    No need to apologize. It's just that making your code hard to read (which not following conventions tends to do) may result in getting less help. And getting help is what this place is for!
     
     
    subject: EL: using variable within an array-variable
     
    Similar Threads
    How to use Break / exist statement here in foreach (JSTL)
    Implementation of google charts in JSP
    Creating a table in a JSP
    JSP Struts/JSTL Form problem
    JSTL paging help required