aspose file tools*
The moose likes Struts and the fly likes Error creating form bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Error creating form bean " Watch "Error creating form bean " New topic
Author

Error creating form bean

vishnu
Greenhorn

Joined: Sep 28, 2002
Posts: 3
[ERROR] RequestUtils - -Error creating form bean of class books.Book <java.lang.ClassCastException: books.Book>java.lang.ClassCastException: books.Book
at org.apache.struts.util.RequestUtils.createActionForm(RequestUtils.java:837)
at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:552)
at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
at org.apache.jsp.CreateBook$jsp._jspService(CreateBook$jsp.java:144)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:484)

I am getting this error for a simple Action class named BookAction and Formbean named Book. Its not ven creating my Action class
My code -
CreateBook.jsp
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html locale="true">
<head>
<html:base/>
</head>
<body bgcolor="white">
<h2>Create a book</h2>
<html:errors/>
<html:form action="createBook.do" method="GET">
Title:<html:text property="title" /> <br/>
<html:submit property="submit"/>
</html:form>
</body>
</html:html>
Book has just some accessor and mutator methods
and BookAction was
package books;
import javax.servlet.http.*;
import org.apache.struts.action.*;
/*
The action for the creation of a book.
@author stephan@stephanwiesner.de
*/
public final class BookAction extends Action
{
/**
@param mapping The ActionMapping used to select this instance
@param form The optional ActionForm bean for this request (if any)
@param req The non-HTTP request we are processing
@param res The non-HTTP response we are creating
@return Return an ActionForward instance describing where and how
control should be forwarded, or null if the response has already
been completed.
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest req,
HttpServletResponse res)
{
System.out.println("Start perform(" + form + ") . . ." );
String title = req.getParameter("title");
Book book = new Book();
book.setTitle( title );
System.out.println("After creation of book: " + book.getTitle() );
req.setAttribute("BOOK", book);
return mapping.findForward("bookCreated");
}
}
[ July 09, 2003: Message edited by: vishnu vardhan ]

vishnu<br />vishnu_d@sify.com<br />SCJP SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
can you also post the part of your struts-config.xml where your BooksAction is performed
Ajit Kanada
Ranch Hand

Joined: Jan 23, 2001
Posts: 95
Hi
I am also facing similar problem..Did anyone get the solution for this problem
Edward Kenworthy
Ranch Hand

Joined: Oct 05, 2003
Posts: 66
Does books.Book sub-class ActionForm ?
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Edward Kenworthy:
Does books.Book sub-class ActionForm ?
Of course it doesn't. Just grab the Struts source and look at RequestUtils line 837, where the stack trace is pointing you, you'd see something along the lines ofThat's pretty unambiguous. Struts is trying to cast to ActionForm, you get a ClassCastException complaining that it's of class Book, hence Book is not an ActionForm.
- Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error creating form bean