I cant set any values in my Action Form for Contact object:
Osgar ali
Greenhorn
Joined: Jan 24, 2009
Posts: 22
posted
0
I am having some issue setting values for Contact object in my form bean. Please see code below:
I have 2 jsps, a.jsp and b.jsp. In a.jsp I am able to see the contact information, when I click on edit, I cant see contact information in b.jsp page
Thanks
public class StudentsForm extends ActionForm{
private String studentId;
private String firstName;
private String lastName;
private ContactVO contact;
public ContactVO getContact() {
return contact;
}
public void setContact(ContactVO contact) {
this.contact = contact;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
contact = new ContactVO();
}
Please disable smilies and put your code in code tags--makes things much, much easier to read.
Without seeing the config it'll be hard to help--the action configuration is (generally) what determines what form is being used, how it's being initialized, etc.
Osgar ali
Greenhorn
Joined: Jan 24, 2009
Posts: 22
posted
0
Thanks David,
Here is the config file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
Please disable smilies and put your code in code tags--makes things much, much easier to read.
You still don't provide the action code that initializes the action form. Do you understand why it's important to include that? Without that code we have no way of knowing if the action is initializing the action form from the ID provided in the edit link.
In the missing action code do you retrieve the appropriate entity from the database? Do you then get the entity object values into the action form?
public class StudentContactAction extends DispatchAction {
private static StudentService stdService = new StudentsDAOService();
private static ContactDAOService contactService = new ContactDAOServiceImp();
private boolean isUpdate(HttpServletRequest request, StudentsForm stdForm) {
boolean updateFlag = true;
//if ID is null or 0 we know we are doing an insert.
String id = stdForm.getStudentId();
if (id == null || id.trim().length() == 0 || Integer.parseInt(id) == 0) {
updateFlag = false;
}
request.setAttribute("updateFlag", Boolean.valueOf(updateFlag));
return updateFlag;
}
(In addition, IIRC copyProperties does only a shallow copy, but I could be mis-remembering that.)
Have you verified that the student is being retrieved correctly? Have you verified that the action form is being correctly set as a result of the copyProperties call?
Osgar ali
Greenhorn
Joined: Jan 24, 2009
Posts: 22
posted
0
Sorry David, I am new to java world and forum. Will make sure in future I will disable simile button.
Yes I am retrieving the values from backend. the first page gets it. It is only when I click on edit I dont see address phone and email but I do see First Name and Last Name
Note that this method is intended to perform a "shallow copy" of the properties and so complex properties (for example, nested ones) will not be copied.
The information that the shallow attributes (first and last name) were visible was important and pertinent information and should have been included the first time--it would have saved a lot of trouble: Tell The Details. It's still not a Struts issue, though.
Osgar ali
Greenhorn
Joined: Jan 24, 2009
Posts: 22
posted
0
Thanks David, yes you are right. I ran it in debug when, I copy student into studentForm it copies only first and latname ,contact object is not copied. Learned something new about shallow and deep copying.
It there any way in struts which allows me to do the deep copy.