• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Form Object and Model Object

 
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.
 
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.
 
Marshal
Posts: 69820
278
  • 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.
 
You've gotta fight it! Don't give in! Read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic