2013-10-23 103 views
0

當我打印studentForm時,這些值是正確的,但信息爲空。這有什麼問題?爲什麼是空?價值的傳遞有什麼問題?

StudentForm studentForm = (StudentForm) form; 
StudentStructure info = studentForm.getStudent(); 
StudentDaoFactory.getDaoFactory().getStudentDao().insert(info); 

這是StudentForm

package com.getcare.crud.web; 

import java.util.ArrayList; 
import java.util.Arrays; 
import java.util.List; 

import javax.servlet.http.HttpServletRequest; 

import net.sf.hibernate.mapping.Collection; 

import org.apache.struts.action.ActionForm; 
import org.apache.struts.action.ActionMapping; 

import com.getcare.crud.remote.StudentContactInfoStructure; 
import com.getcare.crud.remote.StudentStructure; 

public class StudentForm extends ActionForm{ 

    private static final long serialVersionUID = 1L; 

    private StudentStructure student = new StudentStructure(); 
    private StudentContactInfoStructure studentContact = new StudentContactInfoStructure(); 


    public void setId(int id){ 
     this.student.setId(id); 
     this.studentContact.setId(id); 
    } 




    public void setStudentid(int studentid) { 
     studentContact.setId(student.getId()); 
     studentContact.setStudentid(studentid); 
    } 





    public void setFirstName(String firstName) { 
     student.setFirstName(firstName); 
    } 





    public void setMiddleName(String middleName) { 
     student.setMiddleName(middleName); 
    } 




    public void setLastName(String lastName) { 
     student.setLastName(lastName); 
    } 




    public void setGender(String gender) { 
     student.setGender(gender); 
    } 





    public void setBirthdate(String birthdate) { 
     student.setBirthdate(birthdate); 
    } 





    public void setCourse(String course) { 
     student.setCourse(course); 
    } 




    public Integer getPhone(){ 
     return studentContact.getPhone(); 
    } 
    public void setPhone(Integer phone){ 
     student.setPhone(phone); 
     studentContact.setPhone(phone); 
    } 



    public String getAddress(){ 
     return studentContact.getAddress(); 
    } 
    public void setAddress(String address){ 
     studentContact.setAddress(address); 
     student.setAddress(address); 
    } 




    public void setClassCode(Integer classCode) { 
     student.setClassCode(classCode); 
    } 




    public void setStudents(ArrayList students) { 
     student.setStudents(students); 
    } 





    public void setStudentContacts(ArrayList studentContacts) { 
     studentContact.setStudentContacts(studentContacts); 
    } 




    public void setStudentContact(StudentContactInfoStructure studentContact) { 
     studentContact.setContact(studentContact); 
    } 



    public void setStudent(StudentStructure student) { 
     student.setStudent(student); 
    } 




    public int getId() { 
     return student.getId(); 
    } 
    public Integer getStudentid() { 
     return studentContact.getId(); 
    } 
    public String getFirstName() { 
     return student.getFirstName(); 
    } 
    public String getMiddleName() { 
     return student.getMiddleName(); 
    } 
    public String getLastName() { 
     return student.getLastName(); 
    } 
    public String getGender() { 
     return student.getGender(); 
    } 
    public String getBirthdate() { 
     return student.getBirthdate(); 
    } 
    public String getCourse() { 
     return student.getCourse(); 
    } 
    public Integer getClassCode(){ 
     return student.getClassCode(); 
    } 
    public ArrayList getStudents() { 
     return student.getStudents(); 
    } 
    public ArrayList getStudentContacts() { 
     return studentContact.getStudentContacts(); 
    } 
    public StudentContactInfoStructure getStudentContact() { 
     return studentContact.getContact(); 
    } 
    public StudentStructure getStudent() { 
     return student.getStudent(); 
    } 


    @Override 
    public void reset(ActionMapping mapping, HttpServletRequest request) { 
     super.reset(mapping, request); 
//  setId(0); 
     setFirstName(null); 
     setLastName(null); 
     setMiddleName(null); 
     setGender(null); 
     setBirthdate(null); 
     setCourse(null); 
     setPhone(null); 
     setAddress(null); 
     setClassCode(null); 
    } 




} 

那麼StudentStructure

package com.getcare.crud.remote; 

import java.io.Serializable; 
import java.util.ArrayList; 

import com.getcare.remote.Structure; 

/** 
* 
* @author clemjon 
* 
* @hibernate.class table="student" 
*/ 

public class StudentStructure extends Structure implements Serializable{ 

    private Integer id; 
    private Integer phone,classCode; 
    private String firstName, middleName, lastName, gender, birthdate, course,address; 
    private ArrayList students; 
    private StudentStructure student = new StudentStructure(); 

    public StudentStructure getStudent() { 
     return student; 
    } 

    public void setStudent(StudentStructure student) { 
     this.student = student; 
    } 

    public ArrayList getStudents() { 
     return students; 
    } 
    public void setStudents(ArrayList arrayList) { 
     this.students = arrayList; 
    } 
    /** 
    * @hibernate.id generator-class="sequence" 
    * @hibernate.generator-param name="sequence" value="student_id_seq" 
    */ 


    public Integer getId() { 
     return id; 
    } 
    public void setId(Integer id) { 
     this.id = id; 
    } 




    /** 
    * @hibernate.property 
    * 
    */ 

    public String getFirstName() { 
     return firstName; 
    } 

    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 




    /** 
    * @hibernate.property 
    * 
    */ 


    public String getMiddleName() { 
     return middleName; 
    } 
    public void setMiddleName(String middleName) { 
     this.middleName = middleName; 
    } 




    /** 
    * @hibernate.property 
    * 
    */ 

    public String getLastName() { 
     return lastName; 
    } 

    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    } 




    /** 
    * @hibernate.property 
    * 
    */ 

    public String getGender() { 
     return gender; 
    } 

    public void setGender(String gender) { 
     this.gender = gender; 
    } 




    /** 
    * @hibernate.property 
    * 
    */ 

    public String getBirthdate() { 
     return birthdate; 
    } 

    public void setBirthdate(String birthdate) { 
     this.birthdate = birthdate; 
    } 



    /** 
    * @hibernate.property 
    * 
    */ 

    public String getCourse() { 
     return course; 
    } 

    public void setCourse(String course) { 
     this.course = course; 
    } 



// /** 
// * @hibernate.property 
// * 
// */ 

    public Integer getPhone(){ 
     return phone; 
    } 

    public void setPhone(Integer phone){ 
     this.phone = phone; 
//  this.contact.setPhone(phone); 
    } 




// /** 
// * @hibernate.property 
// * 
// */ 

    public String getAddress(){ 
     return address; 
    } 

    public void setAddress(String address){ 
     this.address = address; 
//  contact.setAddress(address); 
    } 


    /** 
    * @hibernate.property 
    * 
    */ 

    public Integer getClassCode(){ 
     return classCode; 
    } 

    public void setClassCode(Integer classCode) { 
     this.classCode = classCode; 
    } 



// public StudentStructure safeClone() { 
//  StudentStructure newInstance = new StudentStructure(); 
//  newInstance.copy(StudentStructure.class, this); 
//  return newInstance; 
// } 


} 

而且StudentContactInfoStructure

package com.getcare.crud.remote; 

import java.io.Serializable; 
import java.util.ArrayList; 

import com.getcare.remote.Structure; 

/** 
* 
* @author clemjon 
* 
* @hibernate.class table="studentcontactinfo" 
*/ 

public class StudentContactInfoStructure { 
    private Integer id, phone,studentid; 
    private String address; 
    private ArrayList studentContacts; 
    private StudentContactInfoStructure contact = new StudentContactInfoStructure(); 

    public StudentContactInfoStructure getContact() { 
     return contact; 
    } 
    public void setContact(StudentContactInfoStructure contact) { 
     this.contact = contact; 
    } 
    public ArrayList getStudentContacts() { 
     return studentContacts; 
    } 
    public void setStudentContacts(ArrayList studentContact) { 
     this.studentContacts = studentContact; 
    } 

    /** 
    * @hibernate.id generator-class="sequence" 
    * @hibernate.generator-param name="sequence" value="studentcontact_id_seq" 
    */ 


    public Integer getId() { 
     return id; 
    } 
    public void setId(Integer id) { 
     this.id = id; 
    } 



    /** 
    * @hibernate.property 
    * 
    */ 

    public Integer getPhone(){ 
     return phone; 
    } 

    public void setPhone(Integer phone){ 
     this.phone = phone; 
    } 




    /** 
    * @hibernate.property 
    * 
    */ 

    public String getAddress(){ 
     return address; 
    } 

    public void setAddress(String address){ 
     this.address = address; 
    } 



    /** 
    * @hibernate.property 
    * 
    */ 

    public Integer getStudentid(){ 
     return studentid; 
    } 

    public void setStudentid(Integer studentid){ 
     this.studentid = studentid; 
    } 


} 

我不知道我將要修改。 :D謝謝

+0

您在'info'上使用'Fetch mode join',同時以條件檢索'StudentForm' –

+0

@sᴜʀᴇsʜᴀᴛᴛᴀ - 你是什麼意思? –

+0

可能''studentForm'具有所有的細節,但它仍然沒有'student'。這就是爲什麼信息爲空。 – SudoRahul

回答

0

因爲,studentForm.getStudent()返回null。

+0

但是當我打印studentForm中的所有值時,它會打印。例如studentForm.getId(),它會輸出正確的輸出和它不爲空的先生。 – Clem