This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

forEach tag

 
Popescu Ion
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I have this jsp code:

In the "databases" package i have "DatabaseData" class :


Why i get an error on forEach tag ? Maybe i wrote it wrong. Any ideas? Thnx in advance.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are mixing the JSTL with scriptlets. Use one or the other, not both. They're not intended to mix.

You should move to the Java code to a servlet controller, then forward to the JSP, placing the list in request scope. It will then be easily accessible to the EL and JSTL.
 
Popescu Ion
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You are mixing the JSTL with scriptlets. Use one or the other, not both. They're not intended to mix.

You should move to the Java code to a servlet controller, then forward to the JSP, placing the list in request scope. It will then be easily accessible to the EL and JSTL.


Thnx anyway, but my question was about the loop, what i might wrote wrong in the forEach tag, the rest of the code is insignificant, i wrote it only to test forEach tag. I used once forEach tag to display Strings, but with Object i can't make it, the error say Property 'vectorID' not found on type java.lang.String. Why it can't find the vectorID ? Deployment is good, i already tested it before. Any ideas?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because, as I already said, the JSTL and EL do not mix with scriptlets. The EL cannot access scripting variables.

Putting a scriptlet into a JSP just for testing is sort of OK, but be sure never to do that in production code.

If you want to access list from the EL and JSTL, you'll need to create a scoped variable with it using the request.setAttribute() method.
 
Popescu Ion
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Because, as I already said, the JSTL and EL do not mix with scriptlets. The EL cannot access scripting variables.

Putting a scriptlet into a JSP just for testing is sort of OK, but be sure never to do that in production code.

If you want to access list from the EL and JSTL, you'll need to create a scoped variable with it using the request.setAttribute() method.

OK, thnx, but I have one more request to you, can you write it or change my code, coz i never used request.setAttribute(), and don't know where and how to put it. I appreciate it.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use real words when posting to the forums. Abbreviations such as "coz" in place of "because" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please click this link ⇒ UseRealWords for more information.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will also need to add appropriate getter/setter methods to your java class, so that EL can access them as a java bean.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic