Hi,
trying to adapt to resource class and i have a binary field with @inject. I try accessing the binary field and it says org.apache.sling.models.impl.injectors.ResourcePathInjector Could not retrieve resource at path {{the values stored at the variable }} for field {{property name}}. Since it is required it won't be injected.
So tried adapting to valuemapvalue,error is gone but the property is null or does not exist
any inputs?
Views
Replies
Total Likes
I would say adapt as resource or then read the binary property using InputStream.
I did the same but are you trying to say adapt the property as resource? Can you please elaborate and give some more details on how this can be done
nodeA has property
binaryprop binary value
HI @NitroHazeDev
I meant the image node resources can be adapted/injected as resources/Node and then read jcr:data property
This is a binary property on a node say custom .. and custom is adapted as a resource . @arunpatidar
with that, the value is null
apologies if I am not able to follow
could you please share the content node structure?
Sure ..
/content
/xxx
/page
/jcr:content
/par
/samplenode(node)
(Not a node) binaryproperty binary binaryval
samplenode is adapted as a resource class
Hi Arun
thanks,
Maybe I didn state the concern well.. my concern is more of adapting the node samplenode of my:unstructured type to a resource class via sling model and getting the binary property Into it
what i observed is that other custom properties injected were retrieved but not the binary, I had taken the route of creating init method within sling model and obtaining the binary by reading the property from node path again via resolver.getresource(node path)
that worked but if I do a get on the binary property that does not work
Hi @NitroHazeDev
could you please share your code which you are you using to retrieve Binary property inside init method?
Hi @arunpatidar "samplenode" in the above structure is adapted to a resource, and its properties, path and binaryPath are injected..
@Model(adaptables = Resource.class,defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL)
public class customModel {
@Inject
private String path;
@Self
private Resource resource;
@SlingObject
private ResourceResolver resolver;
@ValueMapValue(injectionStrategy=InjectionStrategy.OPTIONAL)
private Binary binaryProperty;
//Getters for the properties
@PostConstruct
protected void init() {
//use the getter to get the binary property or use this. and no //result
//alternatively use below and it works
content = resolver.getResource(resource.getPath()).adaptTo(Node.class).getProperty("binaryProperty").getStream();
}
}
@arunpatidar so in the above the injections or valuemap for binary does not seem to work
kindly let me know
Views
Replies
Total Likes
Hi @NitroHazeDev
Please check https://stackoverflow.com/questions/16932789/accessing-resource-data-from-jcr-repo
You can try adapting to Property
@ValueMapValue(injectionStrategy=InjectionStrategy.OPTIONAL)
private Property binaryProperty;
Binary b = (null != binaryProperty) ? binaryProperty.getBinary() : null;
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies