wood burning stoves*
The moose likes JSP and the fly likes forEach tag 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 "forEach tag" Watch "forEach tag" New topic
Author

forEach tag

Popescu Ion
Ranch Hand

Joined: Jan 14, 2011
Posts: 33
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.


Sorry for my English, it is not my first language.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61447
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Popescu Ion
Ranch Hand

Joined: Jan 14, 2011
Posts: 33
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

Joined: Jan 10, 2002
Posts: 61447
    
  67

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

Joined: Jan 14, 2011
Posts: 33
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

Joined: Jan 10, 2002
Posts: 61447
    
  67

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

Joined: Jan 10, 2002
Posts: 61447
    
  67

Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
You will also need to add appropriate getter/setter methods to your java class, so that EL can access them as a java bean.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: forEach tag