JSF 구성 요소를 테스트하고 있지만 NullPointerException이 발생합니다. :( 문제 코드는 다음과 같습니다.
@FacesComponent(value="mycomponent0")
public class MyComponent extends HtmlPanelGroup{
MyComponent(){
String a0=this.getAttributes().get("attr0");
}
}
taglib.xml의 태그에는 attr0 속성이 포함되어 있으며 태그 사용법은 다음과 같습니다.
<abc:mycomponent attr0="helloworld"></abc:mycomponent>
그래서 내 질문은 문제의 원인과 처리 방법입니다.
감사
NPE 문제를 해결하는 방법을 알아낼 수있을 것 같습니다.
속성을 얻기 위해 생성자의 본문을 사용하지 않지만 재정의 된 encodeBegin 메서드에서 속성을 가져옵니다.
@Override
public void encodeBegin(FacesContext context) throws IOException {
String id=this.getAttributes().get("id").toString();
System.out.println("debug: attribute id="+id);
String color=this.getAttributes().get("attr0").toString();
System.out.println("debug: attribute attr0="+attr0);
HtmlOutputLabel label0=new HtmlOutputLabel();
label0.setValue("attribute attr0 value="+attr0);
this.getChildren().add(label0);
super.encodeBegin(context);
}
그래서 그것은 효과가 있고 저는이 솔루션에 괜찮다고 생각합니다. 가장 최적의 방법인지 확실하지 않으므로 일부 스 니펫을 공유하십시오 ...
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다