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.
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.
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
getObjects from ObiectPersistent.class
Joined: Feb 15, 2005
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 ]
Joined: Jan 01, 2007
if you are using struts...you should follow struts rules..you are breaking struts rules here...
Joined: Jan 28, 2007
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.