2017-03-19 74 views
0

我有具有PersonalDetails類對象作爲成員的Employee類Spring表單嵌套對象布爾字段是沒有得到解決

public class Employee { 

private long empId; 

private PersonalDetails personalDetails = new PersonalDetails(); 
// getters setters 

PersonalDetails類如下

/** 
* Class represents personal details of an employee 
* 
* <BR> 
* <BR> 
* <B>Supported API: </B>false <BR> 
* <BR> 
* <B>Extendable: </B>false 
*/ 
public class PersonalDetails { 

private String empfirstName, empMiddleName, empLastName, gender, birthPlace, marritalStatus, 
     longMedicalTreatmentDescription, suffix, ethnicity, veteranStatus, prefFirstName, preLastName, birthCountry, 
     citizenship, citizenshipCountry1, citizenshipCountry2, visaType, email; 

private Address permanentAddress, presentAddress; 

private OtherContactDetails emergencyContactDetails; 

private Date dob, visaExp; 

private int age, noOfChildrens, healthVision; 

private Boolean hasPhysicalDisability, hadLongMedicalTreatment, hasFourWheelLiscence, isPresentAddressSame; 

private Passport passportDetails; 

private FatherOrHusband fatherOrHusbandDetails; 

/** 
* @return the empfirstName 
*/ 
public String getEmpfirstName() { 
    return empfirstName; 
} 

/** 
* @param empfirstName 
*   the empfirstName to set 
*/ 
public void setEmpfirstName(String empfirstName) { 
    this.empfirstName = empfirstName; 
} 

/** 
* @return the empMiddleName 
*/ 
public String getEmpMiddleName() { 
    return empMiddleName; 
} 

/** 
* @param empMiddleName 
*   the empMiddleName to set 
*/ 
public void setEmpMiddleName(String empMiddleName) { 
    this.empMiddleName = empMiddleName; 
} 

/** 
* @return the empLastName 
*/ 
public String getEmpLastName() { 
    return empLastName; 
} 

/** 
* @param empLastName 
*   the empLastName to set 
*/ 
public void setEmpLastName(String empLastName) { 
    this.empLastName = empLastName; 
} 

/** 
* @return the gender 
*/ 
public String getGender() { 
    return gender; 
} 

/** 
* @param gender 
*   the gender to set 
*/ 
public void setGender(String gender) { 
    this.gender = gender; 
} 

/** 
* @return the birthPlace 
*/ 
public String getBirthPlace() { 
    return birthPlace; 
} 

/** 
* @param birthPlace 
*   the birthPlace to set 
*/ 
public void setBirthPlace(String birthPlace) { 
    this.birthPlace = birthPlace; 
} 

/** 
* @return the marritalStatus 
*/ 
public String getMarritalStatus() { 
    return marritalStatus; 
} 

/** 
* @param marritalStatus 
*   the marritalStatus to set 
*/ 
public void setMarritalStatus(String marritalStatus) { 
    this.marritalStatus = marritalStatus; 
} 

/** 
* @return the longMedicalTreatmentDescription 
*/ 
public String getLongMedicalTreatmentDescription() { 
    return longMedicalTreatmentDescription; 
} 

/** 
* @param longMedicalTreatmentDescription 
*   the longMedicalTreatmentDescription to set 
*/ 
public void setLongMedicalTreatmentDescription(String longMedicalTreatmentDescription) { 
    this.longMedicalTreatmentDescription = longMedicalTreatmentDescription; 
} 

/** 
* @return the permanentAddress 
*/ 
public Address getPermanentAddress() { 
    return permanentAddress; 
} 

/** 
* @param permanentAddress 
*   the permanentAddress to set 
*/ 
public void setPermanentAddress(Address permanentAddress) { 
    this.permanentAddress = permanentAddress; 
} 

/** 
* @return the presentAddress 
*/ 
public Address getPresentAddress() { 
    return presentAddress; 
} 

/** 
* @param presentAddress 
*   the presentAddress to set 
*/ 
public void setPresentAddress(Address presentAddress) { 
    this.presentAddress = presentAddress; 
} 

/** 
* @return the dob 
*/ 
public Date getDob() { 
    return dob; 
} 

/** 
* @param dob 
*   the dob to set 
*/ 
public void setDob(Date dob) { 
    this.dob = dob; 
} 

/** 
* @return the age 
*/ 
public int getAge() { 
    return age; 
} 

/** 
* @param age 
*   the age to set 
*/ 
public void setAge(int age) { 
    this.age = age; 
} 

/** 
* @return the noOfChildrens 
*/ 
public int getNoOfChildrens() { 
    return noOfChildrens; 
} 

/** 
* @param noOfChildrens 
*   the noOfChildrens to set 
*/ 
public void setNoOfChildrens(int noOfChildrens) { 
    this.noOfChildrens = noOfChildrens; 
} 

/** 
* @return the healthVision 
*/ 
public int getHealthVision() { 
    return healthVision; 
} 

/** 
* @param healthVision 
*   the healthVision to set 
*/ 
public void setHealthVision(int healthVision) { 
    this.healthVision = healthVision; 
} 

/** 
* @return the passportDetails 
*/ 
public Passport getPassportDetails() { 
    return passportDetails; 
} 

/** 
* @param passportDetails 
*   the passportDetails to set 
*/ 
public void setPassportDetails(Passport passportDetails) { 
    this.passportDetails = passportDetails; 
} 

/** 
* @return the suffix 
*/ 
public String getSuffix() { 
    return suffix; 
} 

/** 
* @param suffix 
*   the suffix to set 
*/ 
public void setSuffix(String suffix) { 
    this.suffix = suffix; 
} 

/** 
* @return the fatherOrHusbandDetails 
*/ 
public FatherOrHusband getFatherOrHusbandDetails() { 
    return fatherOrHusbandDetails; 
} 

/** 
* @param fatherOrHusbandDetails 
*   the fatherOrHusbandDetails to set 
*/ 
public void setFatherOrHusbandDetails(FatherOrHusband fatherOrHusbandDetails) { 
    this.fatherOrHusbandDetails = fatherOrHusbandDetails; 
} 

/** 
* @return the hasPhysicalDisability 
*/ 
public Boolean isHasPhysicalDisability() { 
    return hasPhysicalDisability; 
} 

/** 
* @param hasPhysicalDisability 
*   the hasPhysicalDisability to set 
*/ 
public void setHasPhysicalDisability(Boolean hasPhysicalDisability) { 
    this.hasPhysicalDisability = hasPhysicalDisability; 
} 

/** 
* @return the hadLongMedicalTreatment 
*/ 
public Boolean isHadLongMedicalTreatment() { 
    return hadLongMedicalTreatment; 
} 

/** 
* @param hadLongMedicalTreatment 
*   the hadLongMedicalTreatment to set 
*/ 
public void setHadLongMedicalTreatment(Boolean hadLongMedicalTreatment) { 
    this.hadLongMedicalTreatment = hadLongMedicalTreatment; 
} 

/** 
* @return the hasFourWheelLiscence 
*/ 
public Boolean isHasFourWheelLiscence() { 
    return hasFourWheelLiscence; 
} 

/** 
* @param hasFourWheelLiscence 
*   the hasFourWheelLiscence to set 
*/ 
public void setHasFourWheelLiscence(Boolean hasFourWheelLiscence) { 
    this.hasFourWheelLiscence = hasFourWheelLiscence; 
} 

/** 
* @return the isPresentAddressSame 
*/ 
public Boolean isPresentAddressSame() { 
    return isPresentAddressSame; 
} 

/** 
* @param isPresentAddressSame 
*   the isPresentAddressSame to set 
*/ 
public void setPresentAddressSame(Boolean isPresentAddressSame) { 
    if (isPresentAddressSame) { 
     presentAddress = permanentAddress; 
    } 
    this.isPresentAddressSame = isPresentAddressSame; 
} 

/** 
* @return the ethnicity 
*/ 
public String getEthnicity() { 
    return ethnicity; 
} 

/** 
* @param ethnicity 
*   the ethnicity to set 
*/ 
public void setEthnicity(String ethnicity) { 
    this.ethnicity = ethnicity; 
} 

/** 
* @return the veteranStatus 
*/ 
public String getVeteranStatus() { 
    return veteranStatus; 
} 

/** 
* @param veteranStatus 
*   the veteranStatus to set 
*/ 
public void setVeteranStatus(String veteranStatus) { 
    this.veteranStatus = veteranStatus; 
} 

/** 
* @return the prefFirstName 
*/ 
public String getPrefFirstName() { 
    return prefFirstName; 
} 

/** 
* @param prefFirstName 
*   the prefFirstName to set 
*/ 
public void setPrefFirstName(String prefFirstName) { 
    this.prefFirstName = prefFirstName; 
} 

/** 
* @return the preLastName 
*/ 
public String getPreLastName() { 
    return preLastName; 
} 

/** 
* @param preLastName 
*   the preLastName to set 
*/ 
public void setPreLastName(String preLastName) { 
    this.preLastName = preLastName; 
} 

/** 
* @return the birthCountry 
*/ 
public String getBirthCountry() { 
    return birthCountry; 
} 

/** 
* @param birthCountry 
*   the birthCountry to set 
*/ 
public void setBirthCountry(String birthCountry) { 
    this.birthCountry = birthCountry; 
} 

/** 
* @return the citizenship 
*/ 
public String getCitizenship() { 
    return citizenship; 
} 

/** 
* @param citizenship 
*   the citizenship to set 
*/ 
public void setCitizenship(String citizenship) { 
    this.citizenship = citizenship; 
} 

/** 
* @return the citizenshipCountry1 
*/ 
public String getCitizenshipCountry1() { 
    return citizenshipCountry1; 
} 

/** 
* @param citizenshipCountry1 
*   the citizenshipCountry1 to set 
*/ 
public void setCitizenshipCountry1(String citizenshipCountry1) { 
    this.citizenshipCountry1 = citizenshipCountry1; 
} 

/** 
* @return the citizenshipCountry2 
*/ 
public String getCitizenshipCountry2() { 
    return citizenshipCountry2; 
} 

/** 
* @param citizenshipCountry2 
*   the citizenshipCountry2 to set 
*/ 
public void setCitizenshipCountry2(String citizenshipCountry2) { 
    this.citizenshipCountry2 = citizenshipCountry2; 
} 

/** 
* @return the visaType 
*/ 
public String getVisaType() { 
    return visaType; 
} 

/** 
* @param visaType 
*   the visaType to set 
*/ 
public void setVisaType(String visaType) { 
    this.visaType = visaType; 
} 

/** 
* @return the emergencyContactDetails 
*/ 
public OtherContactDetails getEmergencyContactDetails() { 
    return emergencyContactDetails; 
} 

/** 
* @param emergencyContactDetails 
*   the emergencyContactDetails to set 
*/ 
public void setEmergencyContactDetails(OtherContactDetails emergencyContactDetails) { 
    this.emergencyContactDetails = emergencyContactDetails; 
} 

/** 
* @return the visaExp 
*/ 
public Date getVisaExp() { 
    return visaExp; 
} 

/** 
* @param visaExp 
*   the visaExp to set 
*/ 
public void setVisaExp(Date visaExp) { 
    this.visaExp = visaExp; 
} 

/** 
* @return the email 
*/ 
public String getEmail() { 
    return email; 
} 

/** 
* @param email 
*   the email to set 
*/ 
public void setEmail(String email) { 
    this.email = email; 
} 

/* 
* (non-Javadoc) 
* 
* @see java.lang.Object#toString() 
*/ 
@Override 
public String toString() { 
    return "PersonalDetails [empfirstName=" + empfirstName + ", empMiddleName=" + empMiddleName + ", empLastName=" 
      + empLastName + ", gender=" + gender + ", birthPlace=" + birthPlace + ", marritalStatus=" 
      + marritalStatus + ", longMedicalTreatmentDescription=" + longMedicalTreatmentDescription + ", suffix=" 
      + suffix + ", ethnicity=" + ethnicity + ", veteranStatus=" + veteranStatus + ", prefFirstName=" 
      + prefFirstName + ", preLastName=" + preLastName + ", birthCountry=" + birthCountry + ", citizenship=" 
      + citizenship + ", citizenshipCountry1=" + citizenshipCountry1 + ", citizenshipCountry2=" 
      + citizenshipCountry2 + ", visaType=" + visaType + ", email=" + email + ", permanentAddress=" 
      + permanentAddress + ", presentAddress=" + presentAddress + ", emergencyContactDetails=" 
      + emergencyContactDetails + ", dob=" + dob + ", visaExp=" + visaExp + ", age=" + age 
      + ", noOfChildrens=" + noOfChildrens + ", healthVision=" + healthVision + ", hasPhysicalDisability=" 
      + hasPhysicalDisability + ", hadLongMedicalTreatment=" + hadLongMedicalTreatment 
      + ", hasFourWheelLiscence=" + hasFourWheelLiscence + ", isPresentAddressSame=" + isPresentAddressSame 
      + ", passportDetails=" + passportDetails + ", fatherOrHusbandDetails=" + fatherOrHusbandDetails + "]"; 
} 

}

我正在使用彈簧表單標籤來創建註冊表單並添加代碼如下

<label> 
    <form:checkbox path="personalDetails.isPresentAddressSame" /> 
    Present address same as above 
</label> 

因爲我有一個變量personalDetails,它有一個場isPresentAddressSame應該匹配的getter setter方法,但我收到以下錯誤

There was an unexpected error (type=Internal Server Error, status=500). 
Invalid property 'personalDetails.isPresentAddressSame' of bean class [com.hr.foundation.models.doc.models.employee.Employee]: Bean property 'personalDetails.isPresentAddressSame' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter? 

類型爲String等領域用的路徑匹配像personalDetails.firstName但不是這個布爾字段

+1

如果您沒有顯示「PersonalDetails」的代碼,這裏沒有人可以幫助您。 –

+0

完成。如果我包含課程代碼,我認爲這會很糟糕。 –

+0

你省略了getters/setters。我們需要看到這些。 –

回答

0

你沒有包括PersonalDetails c的getter/setter拉斯,但斯普林說這是錯誤的地方。

確保你有這些:

boolean isPresentAddressSame() { ... } 

void setPresentAddressSame(boolean value) { ... } 

你的錯誤很可能之一:

  1. 您無論是在參數使用Boolean或返回類型(注意大寫B

  2. 您使用getPresentAddressame這是隻允許Boolean(注資本B再次),而不是isPresentAddressSame它應該用於boolean(小B)使用。

澄清

變化:

public Boolean isPresentAddressSame() { 
    return isPresentAddressSame; 
} 

public void setPresentAddressSame(Boolean isPresentAddressSame) { 
    if (isPresentAddressSame) { 
     presentAddress = permanentAddress; 
    } 
    this.isPresentAddressSame = isPresentAddressSame; 
} 

到:

public boolean isPresentAddressSame() { 
    return isPresentAddressSame; 
} 

public void setPresentAddressSame(boolean isPresentAddressSame) { 
    if (isPresentAddressSame) { 
     presentAddress = permanentAddress; 
    } 
    this.isPresentAddressSame = isPresentAddressSame; 
} 

再次說明的是,這裏boolean採用小b

+0

我的getter和setter具有'boolean'作爲返回類型和廣告參數。我也嘗試將它們更改爲「布爾」,但它不起作用。 –

+0

那麼,顯示代碼,然後我們可以檢查它。春天沒有理由給你這個錯誤。 – john16384

+0

請看看我已更新個人資料類。 –