NullpointerException Binding does not work JSF bean
I created a simple HtmlInputText
<h:inputText binding="#{IndexBean.objUIInput}" />
Then in my managed bean this is: -
private UIInput objUIInput;
public UIInput getObjUIInput() {
objUIInput.setValue("laala");
return objUIInput;
}
public void setObjUIInput(UIInput objUIInput) {
System.out.println("Set!!");
this.objUIInput = objUIInput;
}
But I always get a NullpointerException. Do I need to do anything on my JSF page? how do we do jsp: usebean setproperty? Please help me.
If you want to change the default state / behavior of the component before displaying, you need to create an instance . That is, at the time of the announcement:
private UIInput objUIInput = new HtmlInputText();
or during construction:
public Bean() {
this.objUIInput = new HtmlInputText();
}
or, as God suggested, using @PostConstruct:
@PostConstruct
public void init() {
this.objUIInput = new HtmlInputText();
}
(which will be executed after building the bean and initializing / configuring all managed properties).
, - - getters/seters. bean, bean .
UIInput#setValue() setter. JSF .
public void setObjUIInput(UIInput objUIInput) {
this.objUIInput = objUIInput;
this.objUIInput.setValue("laala");
}