I new to Java and JSf, am getting null pointer error when accessing a getter value from backing bean in controller.
Here is the code snippet :
JSP;
input text area and am able see the sysout in setter the value submitted from page and not able to access the getter values.
faces-config.xml
<managed-bean>
<managed-bean-name>researchHisttoryController</managed-bean-name>
<managed-bean-class>com.controller.ResearchHisttoryController</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>history</property-name>
<property-class>com.researchhistory.model.ShipmentHistory</property-class>
<value>#{history}</value>
</managed-property>
</managed-bean>
<managed-bean>
Controller class:
private ShipmentHistory history;
//getters and setter followed;
am accessing varaible from ShipmentHistory class
as
getHistory.getTrackNumber; NPE error
ShipmentHistory.java
private String trackNumber;
//getters and setters
can please help me out where am doing wrong. Thanks for your time.
Then
#{history}is justnull. Apparently you haven’t declared it as a managed bean.But this is kind of odd. A model should not be treated as a controller. Depending on the functional requirement, there must surely be better ways. Perhaps you just want a new blank instance of
ShipmentHistoryeverytime when theResearchHisttoryControllerget created. In that case, do the job in the (post)constructor of the backing bean instead.(please note that you’ve a typo in the backing bean class name)