This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL - forEach inside another forEach" Watch "JSTL - forEach inside another forEach" New topic
Author

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
Bartender

Joined: Oct 14, 2005
Posts: 18715
    
    8

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
Marshal

Joined: Jan 10, 2002
Posts: 61457
    
  67

${expressao}


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSTL - forEach inside another forEach