This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Error creating form bean of class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Error creating form bean of class" Watch "Error creating form bean of class" New topic
Author

Error creating form bean of class

Ram Murthy
Ranch Hand

Joined: Aug 02, 2005
Posts: 91
Hi ,
I am new to STRUTS and am trying to work out an example from a PDF "StrutsSurvival Guide" PDF by Srikanth Shenoy. When I execute the example I get the following error on the internet browser..

<<javax.servlet.ServletException: Exception creating bean of class java.mybank.app1.CustomerForm: {1}>>

and in the Eclipse console see a similar error with additional line on Null pointer exception

<< SEVERE: Error creating form bean of class java.mybank.app1.CustomerForm
java.lang.NullPointerException >>

Listed below is part of my struts-config.xml

struts-config.xml - Extract
===========================

<struts-config>

<form-beans>
<form-bean name="CustomerForm"
type="java.mybank.app1.CustomerForm"/>
</form-beans>


<!-- =========================================== Global Forward Definitions -->

<global-forwards>
<forward
name="mainpage"
path="index.jsp"/>
</global-forwards>


<!-- =========================================== Action Mapping Definitions -->

<action-mappings>
<action path="/submitCustomerForm" name="CustomerForm"
type="java.mybank.app1.CustomerAction">
<forward name="success" path="Success.jsp" />
<forward name="failure" path="Failure.jsp" />
</action>
</action-mappings>

<!-- ============================================= Controller Configuration -->

<controller
processorClass="org.apache.struts.action.RequestProcessor"/>


<!-- ======================================== Message Resources Definitions -->

<message-resources parameter="java.mybank.app1.App1Messages" />

</struts-config>

My JSP CustomerDetails.jsp
==========================

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<html:html>
<head>
<html:base/>
</head>

<body>
<html:errors/>
<html:form action="/submitCustomerForm.do">
<bean:message key="prompt.customer.firstname"/>:
<html:text property="firstName" size="16" maxlength="16"/>
<BR>
<bean:message key="prompt.customer.lastname"/>:
<html:text property="lasttName" size="16" maxlength="16"/>
<BR>
<html:submit>
<bean:message key="button.save"/>
</html:submit>
 
<html:cancel>
<bean:message key="button.cancel"/>
</html:cancel>
</html:form>
</body>
</html:html>

The CustomerForm class
======================

package java.mybank.app1;

import org.apache.struts.action.ActionForm;

public class CustomerForm extends ActionForm{

private String firstName;
private String lastName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}

}

Can anyone figure out what I am doing wrong and why this error is occuring.

Any help will be greatly appreciated.

Thanks,
Ram


Cheers,
Ram
Manuel Sanchez Iba�ez
Greenhorn

Joined: Jul 12, 2005
Posts: 20
<html:text property="�lasttName?" size="16" maxlength="16"/>
Ram Murthy
Ranch Hand

Joined: Aug 02, 2005
Posts: 91
Sorry didn't understand ur response, can anyone explain what is wrong.
Ram Murthy
Ranch Hand

Joined: Aug 02, 2005
Posts: 91
Never mind I understood what you said, I corrected the typo in the lastName..the line was replaced with the one below

<html:text property="lastName" size="16" maxlength="16"/>

I saved it and restarted tomcat but still get the same error..

javax.servlet.ServletException: Exception creating bean of class java.mybank.app1.CustomerForm: {1}
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.CustomerDetails_jsp._jspService(CustomerDetails_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

Can anyone please help...

Thanks,
Ram
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In my experience this error is generally caused by one of the following:

1. There is no public, no-arguments constructor for the ActionForm bean.
2. There is a public constructor, but it's throwing an exception.
3. The bean should exist already in the specified scope, but it doesn't. Sometimes just instantiating the bean and putting it in the correct scope before forwarding to the JSP can solve the problem.
[ January 10, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Ram Murthy
Ranch Hand

Joined: Aug 02, 2005
Posts: 91
I understand the first two points about constructors. I have listed my ActionForm class earlier and I am listing it again.. since I have not declared any constructor, it will automatically create the no-arg constructor. I am not sure what the 3 rd point you have mentioned means. The CustomerDetails.jsp listed in my initial querry is the first jsp I am invoking from my browser.

<<
package java.mybank.app1;

import org.apache.struts.action.ActionForm;

public class CustomerForm extends ActionForm{

private String firstName;
private String lastName;

public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}

}
>>

What is driving me crazy is the error message , it is so cryptic not sure what I should look for based on this message...

javax.servlet.ServletException: Exception creating bean of class java.mybank.app1.CustomerForm: {1}
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)


Rgeards,
Ram
Ram Murthy
Ranch Hand

Joined: Aug 02, 2005
Posts: 91
Never mind, I created the classes again in a different package and it worked. Not sure the root cause but think since my classes were in the package starting with the name java, it was not working.

Thanks for all the responses

Cheers,
Ram
Matt Tyson
Greenhorn

Joined: Jun 29, 2006
Posts: 5
This is the exact same error I've been beating my head against for a couple days now. Never seen it before. I have narrowed the project down to the simplest struts app, just 1 form, 1 action and 1 jsp.

I've tried recreating the project with a different package structure.

Its a rough error.

Here's the struts-config.xml (relavant parts, rest is empty):

<form-beans>
<form-bean name="QueueViewForm" type="webview.struts.form.QueueViewForm" />
</form-beans>

...

<action-mappings>

<action path="/QueueViewSetup"
name="QueueViewForm"
type="webview.struts.action.QueueViewSetup"
scope="request" validate="true" input="/webpages/queueView/queueView.jsp" />

</action-mappings>

...And here's the very ambitious jsp:

<html:form action="/QueueViewSetup">

</html:form>

...And here's the form bean:

package webview.struts.form;

import org.apache.struts.action.ActionForm;

public class QueueViewForm extends ActionForm {

}

... And the action:

package webview.struts.action;
import org.apache.struts.action.Action;

public class QueueViewSetup extends Action {

}

... and of course the mysterious error:

18:37:52,281 ERROR [RequestUtils] Error creating form bean of class webview.struts.form.QueueViewForm
java.lang.NullPointerException


... I never thought I'd be this guy, but here it is: HELP!

Thanks.

Matt
Matt Tyson
Greenhorn

Joined: Jun 29, 2006
Posts: 5
Alright... for the poor guy who comes after me on this one... Adding '.do' to the end of the action on the JSP took care of this.
Matt Tyson
Greenhorn

Joined: Jun 29, 2006
Posts: 5
Hm... turns out that didn't fix it.
Kothandaraman Narashimman
Greenhorn

Joined: Jul 02, 2008
Posts: 4
Try to restart the IDE which you are using. I got the same issue then it got resolved after restarting my eclipse.

Thanks & Regards,
Kothandaraman N.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

My guess is the original poster has already started their IDE at least once in the intervening 2.5 years.
Kothandaraman Narashimman
Greenhorn

Joined: Jul 02, 2008
Posts: 4
Actually i got the same type of situation with the same issue. so i'm trying to help the user's who are all getting this issue in future. May be you got that in wrong way..

Cheers,
Kodan.
Artur Grigoryan
Greenhorn

Joined: Oct 30, 2009
Posts: 1
I had the same problem and the cause was refactoring of my formbean. I changed the name to previous and the issue was resolveded.
Haris Farooque
Greenhorn

Joined: Nov 30, 2009
Posts: 6
hi all,
I am having the same problem here with my CompanyRegistrationForm and CompanyRegistrationAction. amazing fact is that, I have successfully made 2 other forms and their actions and they are working fine but i don't what is wrong with my 3rd form(CompanyRegistrationForm) i have checked all the settings in struts-config.xml and in the companyRegistration.jsp and i didn't find anything wrong there. also thre are no Typo mistakes in any of these files.
Please suggest something if any of you have experienced similar issue before.

cheers

Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Haris, please start a new topic for your question, and in the new topic, post the relevant portions of your struts-config.xml file, the form bean class' code and the action class' code. When you post any source code, remember to UseCodeTags i.e. wrap your code in [code] [/code] tags...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Srivarsini Rangarajan
Greenhorn

Joined: Mar 30, 2012
Posts: 1
Hi all,

Hope you have got a solution for this problem.

Just try including the below taglib and try it.

<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

Cheers,
Sri
 
Don't get me started about those stupid light bulbs.
 
subject: Error creating form bean of class
 
Similar Threads
Cannot retrieve definition for form bean RegisterationForm on action /ShowWelcomePage
Struts validation not working
InvalidCancelException in Struts 1.1
problem in accessing a list through a iterate tag.
tag libs