1

I'm wondering if the following is possible:

<c:forEach var="y" begin="0" end="${amountY }">
            <c:forEach var="x" begin="0" end="${amountX }">

                ${${x }-${y } }
            </c:forEach>
            <br />
        </c:forEach>

I have already set a certain amount of attributes with names being as follows:

"an x value" + "-" +"a y value"

The point of the foreach is to call on these attributes but I don't know beforehand how many there will be.

Now I'm wondering if there's a way to do this with maybe a different syntax cus it's not working this way.

Otherwise is it maybe possible to fill a list with strings and have each string be a certain piece of html code. Then foreaching that list so the strings get implemented as html? Probably not but w/e.

Beau Grantham
  • 3,419
  • 5
  • 32
  • 43
BRNTZN
  • 434
  • 1
  • 7
  • 21

1 Answers1

0

You can't nest el expressions like that.

First use <c:set> to create a new EL variable.

<c:set var="name" value="${x}-${y}" />

Then use it as key to access the attribute value in a specific scope, e.g. ${requestScope}, or ${sessionScope}, or ${applicationScope}, depending on where you stored the actual values.

E.g. if it's in the request scope:

${requestScope[name]}

Needless to say that this is awkward design. Consider using a collection of maps or beans instead.

BalusC
  • 1,040,783
  • 362
  • 3,548
  • 3,513
  • 1
    You're welcome. Since you're new here, don't forget to mark the answer accepted whenever it helped (most) in understanding and solving the concrete problem as stated in the question. See also [How does accepting an answer work?](http://meta.stackexchange.com/a/5235) – BalusC Jul 11 '15 at 21:01