This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Struts and the fly likes Exception creating bean of class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Exception creating bean of class " Watch "Exception creating bean of class " New topic
Author

Exception creating bean of class

Simionu Ursache
Greenhorn

Joined: Jan 28, 2007
Posts: 20
Hi there !

I am getting this error when accesing pages/tiles/bodys/PersonalBody.jsp (see stuts-config.xml)


I have the following configuration:

struts-config.xml:


class databeans.Personal:


Is there a problem because my Personal class extentds ObiectPersonal class and it should extend ActionForm ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Did you check PersonalBody_jsp.java, line 307 ? (it's the translated version of your jsp file).


[My Blog]
All roads lead to JavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

Please be sure to ask Struts question in the Struts forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Milan Jagatiya
Ranch Hand

Joined: Jan 01, 2007
Posts: 164
well, your form bean must sub class of ActionForm.


Milan.<br />I can because I think I can...
Simionu Ursache
Greenhorn

Joined: Jan 28, 2007
Posts: 20
so if i extend the class to ActionForm how can i still use the relation to ObiectPersistent class ?
Milan Jagatiya
Ranch Hand

Joined: Jan 01, 2007
Posts: 164
i am not getting your problem actually why you want to relate ObiectPersistent in actionForm bean. ....
use ActionForm only for communicate controller and view....
Please describe your problem....
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In Struts, it's generally a good idea to have two different objects -- one that is part of the Model, and may be persistent, such as your Personal bean. The other is the ActionForm. They may have the same property names, but the ActionForm properties will be Strings, while the model object properties may be numeric datatypes. The commons BeanUtils class that is included with Struts has a handy method copyProperties that will copy all properties of the same name from one bean to another.

A Struts ActionForm bean does not handle data types like BigDecimal. So, your Personal bean wouldn't work as an ActionForm anyway, even aside from the inheritance problem.


Merrill
Consultant, Sima Solutions
Simionu Ursache
Greenhorn

Joined: Jan 28, 2007
Posts: 20
Ok...so here is the scenario :

I have two tables that keeps info's about Departments(Compartimente) of a company and staff (Personal) of every department. The relation between these two is held by relational column compartid.

For every table i have created a control class (Personal.class , Compartimente.class) with setter and getter methods. This classes are extending the ObiectPersistent.class in which i do the insert, update, delete methods of the records.

Personal.class


Compartimente.class


I would like to see in a page all the staff from one department. so i have a first form with a select option that show all the departments and a refresh button. When i click the refresh button, the second form on the page load the info about the staff from the compartiment selected.

Here is the source:


I can see the list of compartiments, but when i click the refreh button i get the error.

Other files:
struts-config.xml


CompartPersSelectedBean.class


SelectAngajatAction.class


getObjects from ObiectPersistent.class
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since you're not using the Personal bean as the form bean for an Action class, it is completely unneccessary to define it as a form bean at all. Remove the line:

from your struts-config.xml file and it should work.

A couple of observations, though:

1. It is considered very bad form to include database access code in a JSP as you have done. Struts is a Model/View/Controller framework that helps you separate these three functions into separate componenents. By putting database access code in your JSP, you're mixing model logic into a view component.

2. If you read a bit about the <htmlptionsCollection> tag, you will see that it is much easier to use this tag than the method you're using. Here is the link to the documentation.
[ February 01, 2007: Message edited by: Merrill Higginson ]
Milan Jagatiya
Ranch Hand

Joined: Jan 01, 2007
Posts: 164
if you are using struts...you should follow struts rules..you are breaking struts rules here...
Simionu Ursache
Greenhorn

Joined: Jan 28, 2007
Posts: 20
I have solved the problems but got into another one. Now when i submit the date i get a blank .do page

If i go back and the refresh(F5) the data that should be displayed is displayed!

And this happens at all pages. I have done a very simple login page that just outputs the entered data and everything is ok.

Do you have any ideas ?
Simionu Ursache
Greenhorn

Joined: Jan 28, 2007
Posts: 20
could it be a bug of Struts ?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exception creating bean of class
 
Similar Threads
Unable to create form bean
Getting exception on deployment to Tomcat using JSF
javax.servlet.ServletException: Name java: is not bound in this Context
javax.servlet.ServletException: Exception creating bean of class
Error in deploying struts: Attribute name invalid according to the specified TLD