I have two classes of managed beans and use @ManagedProperty
to try to access the second one but I get NullPointerException
every time. What is the problem here?
@ManagedBean
@SessionScoped
public class EventCreateEditModel implements Serializable {
@ManagedProperty("#{eventCreateEditCostModel}")
private EventCreateEditCostModel eventCreateEditCostModel;
public void update() {
eventCreateEditCostModel.update();
}
public void setEventCreateEditCostModel(final EventCreateEditCostModel eventCreateEditCostModel) {
this.eventCreateEditCostModel = eventCreateEditCostModel;
}
public EventCreateEditCostModel getEventCreateEditCostModel() {
return eventCreateEditCostModel;
}
}
Here is my second class.
@ManagedBean
@SessionScoped
public class EventCreateEditCostModel implements Serializable {
public void update() {
System.out.println("IT works");
}
}
I try to get the first class to call the second class update using @ManagedProperty
but all I get is NullPointerException
, when I try to access the update from the first class. I do have setters and getters for the @ManagedProperty
.
Here is the stack trace which points to the update method in class EventCreateEditModel (tried to paste the whole stack but this system will not format it so here are the key parts)
`Dec 24, 2015 2:02:57 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: java.lang.NullPointerException
javax.el.ELException: java.lang.NullPointerException
at com.sun.el.parser.AstValue.invoke(AstValue.java:238)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
Caused by: java.lang.NullPointerException
at com.rem40.controller.EventCreateEditModel.update (EventCreateEditModel.java:116)
... 35 more
Dec 24, 2015 2:02:57 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError SEVERE: java.lang.NullPointerException at com.rem40.controller.EventCreateEditModel.update(EventCreateEditModel.java:116) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)`