This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes JSTL - forEach inside another forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL - forEach inside another forEach" Watch "JSTL - forEach inside another forEach" New topic

JSTL - forEach inside another forEach

Josh Borg
Ranch Hand

Joined: Oct 02, 2012
Posts: 32

I was rewriting my scriptlet JSP to Expression Language and JSTL, but it seems not to work. I have an ArrayList with 3 classes named 'expressao', I want to use foreach to iterate each one and get the values 'numero' from it. For me the syntax is okay, but it's not working for some reason. Something wrong?

Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Welcome to the Ranch, Josh!

Well, first of all in line 5, the EL variable you want to iterate through is the one which is the request attribute. It's called "expressao". (The scriptlet variable "expressoes" is not accessible to EL code.) So:

(Sorry if I mangled your Portuguese variable names -- it looks to me like "expressao" is singular so it wasn't a good choice for a list of things.)

Then each "expressaoItem" is an Equacao object. I don't know what that is or whether iterating through it makes any sense. I'm going to suppose it has a getNumero() method, in which case you wouldn't iterate over it. You would just use

to get that value. On the other hand if it has a getNumeros() method which returns an array or List of something, then you iterate over this list like this:

and then you use the "numero" variable to represent each element of that array or List.
Josh Borg
Ranch Hand

Joined: Oct 02, 2012
Posts: 32

Thanks for the welcome and thanks for the answer, you are right the word 'expressao', I should use 'expressoes' that is the plural, my mistake, glad you know a little of portuguese. :)

So, from what I understood in your explanation, I did all right, except by the fact that I was trying do get a value from Scriptlet, in my EL. The problem is that I must send data by request.setAtribute to JSP, because this system has not database, for my JSP page get the processed information in my servlet. The system consists in: Send an text to servet, and receive an answer. If I can't exchange data from Scriptlet to EL (I can not, right?), there is anyway to do same thing using EL (request.getAttribute("expressao"))? :thumbup:
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60794


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
subject: JSTL - forEach inside another forEach
Similar Threads
Iteration of List in JSP
c:forEach fails along with "${var}" syntax
c:forEach is not working
How to convert the for Loop to the equalent JSTL code in JSP
Using Two ArrayLists For One Table