• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to work with pojo and actionform

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
I am very confuse that how i should use POJO in actionform
In order to provide for clean separation between tiers, web application architectures often include delegates, proxies, or fa�ades that can be called from the web tier to store and retrieve data.Often, the lower tier uses
POJOs as data transfer objects (DTOs).

Now there are 2 ways to define actionform
now this is our DTO :
Employee pojo
public class Employee implements Serializable

{

private static final long serialVersionUID = 1L;

private Integer employeeNumber;

private String firstName;

private String lastName;

..

public Integer getEmployeeNumber() {

return employeeNumber;
...
}

1.
public class EmployeeForm extends ActionForm implements Serializable{
private static final long serialVersionUID = 1L;
private Employee employee;
...
}
2.

public class EmployeeForm extends ActionForm implements Serializable{
private static final long serialVersionUID = 1L;
private Integer employeeNumber;

private String firstName;

private String lastName;
..(all the properties whic are there in pojo)
...
}
I just want to ask what is the best approach?


thanks,
Nishita
 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Nishita,

The best approach depends upon your requirement. If first name, last name etc you are entering through jsp pages, you are doing validations and displaying differenct messages. Then second approach is better else first.

Thanks,
Vivek
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would cast a vote for #2. A better example would be if your Employee pojo class had a Double or double value for salary. Struts 1.x needs to have String values in the form to support validation. I have played a little with Struts 2.x and some other frameworks that interact better with pojos and do not have this requirement.

If you did go for #1 you have to remember to create a new Employee class somewhere if your form uses request scope. This could be your constructor, the declaration or in your getEmployee() method. Struts would not call your setEmployee() method. Instead it would make a call like getEmployee().setFirstName("Brent"), which would blow up if getEmployee() returns null.

- Brent
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic