2017-04-09 1 views
0

특정 개체에서 머리글 이름과 필요한 속성을 지정하여 동적 눈금을 만드는 데 참조로이 설명서 예제를 사용하고 있습니다. http://jxls.sourceforge.net/samples/dynamic_grid.htmlJXLS 동적 격자 throw null null NestedNullException

하지만 내 경우에는 Employee 개체가 중첩 된 속성 "adres.housenumber"

public class Employee { 
    private String name; 
    private Date birthDate; 
    private BigDecimal payment; 
    private BigDecimal bonus; 
    private Adres adres; 
    // constructors and getters/setters 
    ..... 
} 

public class Adres { 
    private String housenumber; 
} 

모든 직원이하는 housenumber와 직원이 ADRES이있는 경우, 나는 예외 아래에있어 adres이있는 경우 그것은 잘 작동 : org.apache.commons.beanutils.NestedNullException :

에 의한 빈 클래스 '수준의 직원'

에 'adres.housenumber'에 대한 널 (null) 속성 값 org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty (PropertyUtilsBean.java:795)에서

~ [몬즈 beanutils-1.9.3.jar : 1.9.3]
org.apache.commons.beanutils.PropertyUtilsBean에서 .getProperty (PropertyUtilsBean.java:884) ~ [commons-beanutils-1.9.3.jar : 1.9.3]
at org.apache.commons.beanutils.PropertyUtils.getProperty (PropertyUtils.java:464) ~ [commons- beanutils-1.9.3.jar : 1.9.3]
org.jxls.command.GridCommand.processBody (GridCommand.java:185) ~ [jxls-2.3.0.jar :?]
at org.jxls. command.GridCommand.applyAt (GridCommand.java:137) ~ [jxls-2.3.0.jar :?]
at org.jxls.area.XlsArea.applyAt (XlsArea.java:168) ~ [jxls -2.3.0.jar :?] org.jxls.util.JxlsHelper.processGridTemplate (JxlsHelper.java:156) ~ [jxls-2.3.0.jar :?]에서

직원이 데이터는 데이터베이스에서 검색하여 Excel로 내보내기 전에 전달하기 전에 수정할 수있는 액세스 권한이 없습니다.

어떤 아이디어/도움주세요?

답변

0

null 속성 집합이있을 때 속성의 속성을 평가하려고 할 때 문제가 GridCommand로 인해 발생합니다. 따라서 Apache PropertyUtils (GridCommand에서 사용)는 Exception을 던집니다.

example 속성에서 Employee 클래스의 adres는 null이므로 adres.housenumber를 평가하면 예외가 발생합니다.

이 동작을 피하려면 bean 대신 Iterable 객체를 사용할 수 있습니다. 이런 식으로 GridCommand는 소품을 평가하지 않고 Iterable 객체에 값을 묻습니다.

나는이 프로젝트가 어떻게 작동하는지 보여주기 위해이 프로젝트를 수행했다. https://github.com/LucianoZu/jxlsnofault

IterableWrapper 클래스를 사용하면 Employee를 래핑하고 예외를 피할 수 있습니다.