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,435
  • 5
  • 33
  • 43
BRNTZN
  • 564
  • 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,082,665
  • 372
  • 3,610
  • 3,555