changing value of UIComponent in Program
I have a backing bean in which there is a private HtmlOutputText firstName component. In the constructor of the backing class I am trying to set its value as given below
private HtmlOutputText firstName;
public EmployeeOutput() {
firstName.setValue("Jatin");
}
This is giving me the following exception
Can't instantiate class: java.lang.NullPointerException
What is wrong with the above code ?
# 1
A NullPointerException simply means that the related object is still null and therefore you cannot invoke actions on it.
The solution is very simple:
if (someObject == null) {
someObject = new SomeObject();
}
someObject.invokeAction();
Or just initialize it right in the property field:private SomeObject someObject = new SomeObject();
Then you don't need to do a null check.
I would say, please restart reading some Java tutorials or do some courses. This is really basic Java knowledge ;)
# 2
I am a bit coufused about the creating new object(in this context). When I processed my input JSF page, I don't create any objects for HtmlInputText, still I was able to access its value(bound to JSP page).