• 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: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I've seen this error posted several times, but I haven't been able to resolve it. I'm trying to get a tutorial to work without much success. The error I'm getting is "Cannot find bean book in any scope". Can someone please take a look at this and let me know what the problem might be. I appreciate any and all responses.


****** bookList.jsp ******

<logic:notEmpty name="bookListForm" property="books">
<logic:iterate name="bookListForm" property="books" id="books">
<tr>
<%-- print out the book information --%>
<td><bean:write name="book" property="author"/></td>
<td><bean:write name="book" property="title"/></td>
<td><html:checkbox disabled="true" name="book" property="available"/></td>
<%-- print out the edit and delete link for each book --%>
<td>
<html:link action="bookEdit.do?do=editBook" paramName="book" paramProperty="id" paramId="id">Edit</html:link>
</td>
<td>
<html:link action="bookEdit.do?do=deleteBook" paramName="book" paramProperty="id" paramId="id">Delete</html:link>
</td>
</tr>
</logic:iterate>
</logic:notEmpty>

****** ActionForm *******

public class BookListForm extends ActionForm {

private Collection books;

//get the collection of books
public Collection getBooks() {
return books;
}

public void setBooks(Collection books) {
this.books = books;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {
books = new ArrayList();
}
}


******* Action class **********

public class BookListAction extends Action {

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {

BookListForm bookListForm = (BookListForm) form;

//init SimulateDB class and set some dummy data
SimulateDB simulateDB = new SimulateDB();
bookListForm.setBooks(simulateDB.getAllBooks(request.getSession()));

return mapping.findForward("showList");
}
}

**** struts-confi.xml *******
<struts-config>
<data-sources />

<form-beans >
<form-bean name="bookListForm" type="de.laliluna.tutorial.library.struts.form.BookListForm" />
<form-bean name="bookEditForm" type="de.laliluna.tutorial.library.struts.form.BookEditForm" />
</form-beans>

<global-exceptions />

<global-forwards >
<forward name="welcome" path="/default.do" redirect="true" />
</global-forwards>

<action-mappings >
<action forward="/jsp/index.jsp" path="/default" unknown="true"/>
<action attribute="bookListForm" input="/jsp/bookList.jsp" name="bookListForm" path="/bookList"
scope="request" type="de.laliluna.tutorial.library.struts.action.BookListAction" validate="false">
<forward name="showList" path="/jsp/bookList.jsp" />
</action>
<action attribute="bookEditForm" name="bookEditForm" parameter="do" path="/bookEdit" scope="request"
type="de.laliluna.tutorial.library.struts.action.BookEditAction">
<forward name="showEdit" path="/jsp/bookEdit.jsp" />
<forward name="showList" path="/bookList.do" redirect="true" />
<forward name="showAdd" path="/jsp/bookAdd.jsp" />
</action>
</action-mappings>

<message-resources parameter="de.laliluna.tutorial.library.struts.ApplicationResources" />
</struts-config>

****** error ******

javax.servlet.jsp.JspException: Cannot find bean book in any scope
at org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:938)
at org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:286)
at org.apache.jsp.jsp.bookList_jsp._jspx_meth_bean_005fwrite_005f0(bookList_jsp.java:267)


******************

Thank you for any help you can provide.

Elden
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Elden,
Welcome to JavaRanch!


There's a typo in this code snippet. The id should be "books", not "book." The id is the variable name of the value for that iteration of the loop. It is referred to as "book" within the loop.
 
E Fontes
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne,

Your reply was very helpful. You said the id in the code snippet should be "books" and not "book", but actually the id should be "book" and not "books". Your solution pointed me in the right direction and once I changed the id it worked fine.

Thank you for your quick reply.

Elden
 
reply
    Bookmark Topic Watch Topic
  • New Topic