Results 1 to 1 of 1
- 02-08-2011, 05:50 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 40
- Rep Power
- 0
Struts action form not returning object
All right guys, I am working on this project where there are 2 classes, Customer and Address which has a one to one relationship.(Customer has an Address)
I created a Customer Action form which returns a customer object and since the address is part of Customer object, I added Address setters/getters inside the Customer form (though they are 2 separate entity classes). But for some reason, I cant return address from the Customer form. Its getting null value. I have the getters/setters for both customer and address inside the form and getCustomer() works fine but not getAddress().
Is it Ok to include 2 objects inside a single Struts form?
These are my codes:
This is my Customer Action class which calls the form:Java Code:public class CustomerForm extends org.apache.struts.action.ActionForm { public static Logger logger = Logger.getLogger(CustomerForm.class); private Customer customer = new Customer(); private Address address = new Address(); public CustomerForm() { super(); } public Customer getCustomer() { System.out.println("inside customer form"); return customer; } public int getId() { return customer.getId(); } public void setId(int id) { customer.setId(id); } public String getFirstName() { return customer.getFirstName(); } public void setFirstName(String firstName) { customer.setFirstName(firstName); } public String getLastName() { return customer.getLastName(); } public void setLastName(String lastName) { customer.setLastName(lastName); } public Address getAddress() { return address; } public String getState() { return address.getState(); } public void setState(String state) { address.setState(state); } public String getCity() { return address.getCity(); } public void setCity(String city) { address.setCity(city); } public String getEmail() { return address.getEmail(); } public void setEmail(String email) { address.setEmail(email); } public String getPhone() { return address.getPhone(); } public void setPhone(String phone) { address.setPhone(phone); } public String getStreetAddress() { return address.getStreetAddress(); } public void setStreetAddress(String streetAddress) { address.setStreetAddress(streetAddress); } public String getZipcode() { return address.getZipcode(); } public void setZipcode(String zipcode) { address.setZipcode(zipcode); } }
How do I fix it?Java Code:Customer customer = new Customer(); Address address = new Address(); System.out.println("getting Customer in CustomerActionn"); customer = ((CustomerForm) form).getCustomer(); System.out.println("getting Address in CustomerActionn"); address = ((CustomerForm)form).getAddress(); customer.setAddress(address); System.out.println("street address inside customer action is " +address.getStreetAddress());-------------- this returns null System.out.println("name inside customer action is " + customer.getLastName());----------- this returns lastname System.out.println("street address inside customer action is " + customer.getAddress().getStreetAddress());-------returns null
Similar Threads
-
Need help in returning the action of keystrokes.
By Wx! in forum New To JavaReplies: 1Last Post: 12-27-2010, 11:24 PM -
decorator.jsp problem building Struts Menu in JSP when Struts action is used
By dkirvan in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 04-29-2010, 05:33 AM -
Errors come when i set attribute in request in Action Form
By 82rathi.angara in forum New To JavaReplies: 3Last Post: 09-22-2008, 02:05 PM -
Action class in Struts
By Java Tip in forum Java TipReplies: 0Last Post: 12-27-2007, 10:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks