File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Beans and c:forEach

 
Andrew McLaren
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Andrew McLaren
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1640
9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<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
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic