This week's book giveaway is in the JavaScript forum.
We're giving away four copies of JavaScript Promises Essentials and have Rami Sarieddine on-line!
See this thread for details.
The moose likes JSP and the fly likes Beans and c:forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Beans and c:forEach" Watch "Beans and c:forEach" New topic
Author

Beans and c:forEach

Andrew McLaren
Ranch Hand

Joined: May 27, 2005
Posts: 33
I am having a hard time getting forEach to iterate through a bean I have, which is an array. Here is (I think) the relevant code:
Populate the bean:


The class for the bean:


And the relevant bits of the jsp:


But what I get is javax.servlet.ServletException: Unable to find a value for "dataSourceName" in object of class "java.lang.String" using operator "." I've been running all over the place trying to get this working, but obviously I am missing something. Any advice would be greatly appreciated.

Thanks

Andrew
[ July 06, 2005: Message edited by: Andrew McLaren ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61587
    
  67

through a bean I have, which is an array


Is it a bean or an array? It can't be both.

By "bean" are you really meaning a scoped variable?

Your post appears incomplete. What is the specific problem that you are experiencing?
[ July 06, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Andrew McLaren
Ranch Hand

Joined: May 27, 2005
Posts: 33
Originally posted by Bear Bibeault:


Is it a bean or an array? It can't be both.

By "bean" are you really meaning a scoped variable?

Your post appears incomplete. What is the specific problem that you are experiencing?

[ July 06, 2005: Message edited by: Bear Bibeault ]


Sorry for any misuse of terminology (did I spell that right?), I am pretty new to all this.
And yes, my post was incomplete, managed to cleverly click the add post button, which is in fact no where near the code button, but that didn't stop me...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61587
    
  67

Off the bat, you are setting the scoped variable into request scope:



and yet referencing it from session scope:



These need to be consistent.

The term "bean" means a class that adheres to the JavaBeans conventions. The term for an object placed onto one of the scopes via setAttribute (which is often a bean) is "scoped variable".
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61587
    
  67

which is in fact no where near the code button, but that didn't stop me...


Glad I'm not the only one that does that...

P.S. Another hint: check 'disable smilies' when posting code. That's make your <cut> tags look less surprised.
Andrew McLaren
Ranch Hand

Joined: May 27, 2005
Posts: 33
Ok, I changed it to:


But I still get the exact same error.
I think I need to find a complete example of something similar to what I am doing, I am getting pretty close to winging it here.

Thanks for the explanation of variables vs beans.

Peace

Andrew
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
<c:forEach var="ds" items="${requestScope.dataSource}}">

You have two "}" in your forEach statement there. Is that a typo?

For debugging, check the type of the arguments you are passing in.


The main causes of the error message: Unable to find a value for "dataSourceName" in object of class "java.lang.String" using operator "."
1 - You didn't put ${ } characters in the items attribute of the forEach tag.
2 - The items attribute of forEach tag resolved to a String
3 - the items attribute of forEach tag resolved to a collection/array of Strings.

Hope this helps,
evnafets
Andrew McLaren
Ranch Hand

Joined: May 27, 2005
Posts: 33
Originally posted by Stefan Evans:
<c:forEach var="ds" items="${requestScope.dataSource}}">

You have two "}" in your forEach statement there. Is that a typo?




Arrrgh! I am my own worst enemy, I swear. Yes, it was indeed a typo, and it was in my actual code, not just in my post.
Anyhoo, thanks to everyone for their help.

Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Beans and c:forEach