• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot find bean in any scope...

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranjit your method is not working....
 
Jibitesh Prasad
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yupsie Merylll.. thanks a lot... got the prob [ ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic