• Post Reply Bookmark Topic Watch Topic
  • New Topic

Form Object and Model Object  RSS feed

 
Mandy Ram
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it good to have a single Class for both the Form and Model?

Let me explain with an example.

CompanyForm.java

private int companyId
private String companyName;
private List<EmployeeVO> employeeList;
private List<DeptVO> deptList;

CompanyVo.java

private int companyId
private String companyName;



The CompanyForm.java is actually used to populate the values in the drop downs on the JSP.So, it contains the employee list and department list.

Where as the CompanyVo.java is the one which I use to persist data in the DB and any other business process.


The normal approach I see in many projects is to maintain 2 different Classes as mentioned above.Once the user submits the form,We get the form values in the action/controller in the EmployeeForm.java and then we copy each and every value to EmployeeVo.java

like..


Let us say companyForm.java and companyVo.java contains another 15 variables each. In this case,the copying from form object to value object looks tedious and unnecessarily increase the lines of code and also its difficult to maintain as any change to Form object or value object will effect the code where we do the copy.

Is it not good to have only one class instead of having two different classes(EmployeeForm,EmployeeVo)

If so, Which class should be killed?

Please let me know if am not clear.
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any relation to Sun Java?

I didn't really follow your example, but maybe I was not patient enough to study it thoroughly. In general, a program is easier to maintain and modify if the data is kept separate from the user interface.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cousin of Mandriva Java™, more likely, I would have thought

Your form would have fields like companyNameTextBox and the data mode class would have fields like companyName. Actually, you would more probably put that latter field in a Company class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!