This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error creating form bean of class

 
Ram Murthy
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Manuel Sanchez Iba´┐Żez
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html:text property="´┐ŻlasttName?" size="16" maxlength="16"/>
 
Ram Murthy
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry didn't understand ur response, can anyone explain what is wrong.
 
Ram Murthy
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ram Murthy
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm... turns out that didn't fix it.
 
Kothandaraman Narashimman
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is the original poster has already started their IDE at least once in the intervening 2.5 years.
 
Kothandaraman Narashimman
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Srivarsini Rangarajan
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic