• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL - forEach inside another forEach

 
Josh Borg
Ranch Hand
Posts: 35
Chrome Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
..
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
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
Chrome Eclipse IDE Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${expressao}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic