Facelet 코드 :JSF의 F : 목록 오류를 사용하여 selectItems
<h:selectOneMenu id = "country" label = "country" value = "#{beanController.countryResidence}">
<f:selectItems value = "#{countries.countries}" />
</h:selectOneMenu>
콩 코드 :
@ManagedBean(eager=true, name = "countries")
@ApplicationScoped
public class CountriesConstants {
private List<SelectItem> countries;
public CountriesConstants(){
countries.add(new SelectItem("DE", "Germany"));
countries.add(new SelectItem("JA", "Japan"));
countries.add(new SelectItem("RU", "Russia"));
countries.add(new SelectItem("US", "United States"));
}
public List<SelectItem> getCountries() {
return countries;
}
public void setCountries(List<SelectItem> countries) {
this.countries = countries;
}
}
오류
SEVERE : 예외 응용 프로그램
를로드하는 동안SEVERE: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.mysite.util.CountriesConstants.
나는 몇 가지 자습서를 단계별로 따라 갔지만이 오류가 계속 발생합니다. 리스트 을 정적 인으로 만들고 정적 블록의 값을 초기화하려고 시도했지만 동일한 오류가 발생합니다.
편집 :
새로운 콩 코드
@ManagedBean(eager=true, name="constants")
@ApplicationScoped
public class Constants {
public static final String VALIDATE_DETAILED = "detailed";
public static final List<SelectItem> countries;
static{
countries = new ArrayList<SelectItem>();
countries.add(new SelectItem("DE", "Germany"));
countries.add(new SelectItem("JA", "Japan"));
countries.add(new SelectItem("RU", "Russia"));
countries.add(new SelectItem("US", "United States"));
}
public List<SelectItem> getCountries() {
return countries;
}
}
이 작동하는 것 같다하지만 난 그게 이상한 '비 정적 메서드로 정적 속성에 액세스 할 수 있는지 찾을 수 있습니다. getCOuntries() 메서드를 제거하면 국가 특성이 존재하지 않는다는 오류가 발생합니다.이 발생합니다. 당신의 빈 생성자에서
예외를 얻으려면 항상 스택 추적의 맨 아래 부분을보십시오. 매우 자명 한'NullPointerException'을 가지고 있습니다. – BalusC