@Override
protected void writeForm(PageOverviewForm form, ActionMessages errors, HttpServletRequest request) {
PersonVO person = (PersonVO)getPanel().getEntity();
AddressVO mainAddress = null;
AddressVO postalAddress = null;
// get person addresses
for(AddressVO address : person.getAddresses()) {
if(AddressVO.Type.MAIN.equals(address.getType()) && mainAddress == null) {
mainAddress = address;
} else if(AddressVO.Type.POSTAL.equals(address.getType()) && postalAddress == null) {
postalAddress = address;
}
}
// get company addresses
if(person.getCompany() != null && Hibernate.isInitialized(person.getCompany().getAddresses())) {
for(AddressVO address : person.getCompany().getAddresses()) {
if(AddressVO.Type.MAIN.equals(address.getType()) && mainAddress == null) {
mainAddress = address;
} else if(AddressVO.Type.POSTAL.equals(address.getType()) && postalAddress == null) {
postalAddress = address;
}
}
}
if(mainAddress != null) {
getPanel().setAttribute("mainAddress", mainAddress);
if(mainAddress.getCompany() != null)
getPanel().setAttribute("mainAddressCompany", Boolean.TRUE);
else
getPanel().removeAttribute("mainAddressCompany");
} else {
getPanel().removeAttribute("mainAddress");
getPanel().removeAttribute("mainAddressCompany");
}
if(postalAddress != null) {
getPanel().setAttribute("postalAddress", postalAddress);
if(postalAddress.getCompany() != null)
getPanel().setAttribute("postalAddressCompany", Boolean.TRUE);
else
getPanel().removeAttribute("postalAddressCompany");
} else {
getPanel().removeAttribute("postalAddress");