Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot find bean in any scope...

 
Jibitesh Prasad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a action class which adds an arraylist of Friends object to the request. The action class is invoked from a hyperlink so it doesn't need a form element. Now when i am trying to display the contents of the bean, it gives an error saying
javax.servlet.ServletException: Cannot find bean: "friend" in any scope


The jsp page reads....
<logic:iterate name="user_friends" id="friend" scope="request">
<tr>
<td>
<bean:write name="friend" property="first_name" />
</td>
<td>
<bean:write name="friend" property="last_name" />
</td>
</tr>
</logic:iterate>

The form-bean entry in struts-config.xml file reads:

Can anyone help me with this?
 
Ranjit Gopinathan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try

<logic:iterate name="LoginForm" property="user_friends" id="friend">
..
<bean:write name="friend" property="first_name" />
...
</logic:iterate>

if logic:iterate

Name - is the name of form bean you are declaring in struts-config
property - is the collection object you need to iterate
id - the id you are giving for collection object to be iterated

and when using bean:write

name = id you declared in logic:iterate
property = the variable inside the object from the collection you are iterating.
eg: List friends contains list of objects of type friend.

So when iterating friends you will get a friend object
which will have "first name" variable , with getter/setter methods.

HTH
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the action class that forwards to this JSP.
 
Jibitesh Prasad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Thats my action class
And it is being called from this page
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The action looks OK. Did you remember to include a <%@ taglib> declaration for the logic tag library in your JSP? If you didn't, that would cause this problem.
 
Jibitesh Prasad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranjit your method is not working....
 
Jibitesh Prasad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yupsie Merylll.. thanks a lot... got the prob [ ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic