osgi - Why does the field from parent class has a null value when using in other class (Java/apache sling) -
in java code have following class:
@model(adaptables = slinghttpservletrequest.class) public class listmodel extends somelist{ @inject protected resourceresolver resourceresolver; //this method works fine: public list<string> getalldata(){ system.out.println(resourceresolver.getuserid()); } } when call method getalldata() class, see user's id - fine.
now need write 2nd class extend 1 above. looks this:
public class mynextlistmodel extends listmodel{ //this method throws nullpointer because resourceresolver null - why? @override public list<listitemmodel> getallitems() { system.out.println(resourceresolver.getuserid()); } } how come resourceresolver in 2nd class has null value?
i tried moving code:
@inject protected resourceresolver resourceresolver; from listmodel mynextlistmodel, though, it's still null in 2nd class
if class inheriting model missing @model annotation, sling not know do. add annotation inheriting class , code should work. btw make sure the other class in package registered sling models package in core pom.
Comments
Post a Comment