File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 35

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: 19973

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: 35

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: 63840


[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: JSTL - forEach inside another forEach
It's not a secret anymore!