[
https://issues.apache.org/jira/browse/SLING-8562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16883653#comment-16883653
]
Julian Sedding commented on SLING-8562:
---------------------------------------
[~fortuna] as I said, I am not familiar with the ESP implementation. I took a
look and you are right that my suggestions were incorrect. That's because there
seems to be an explicit mapping between Java and javascript objects rather than
an implicit mapping, which I had expected.
My reading of the source code is that you should be able to call properties
explicitly like so {{currentNode.properties.title}} (or similarly
{{resource.properties.title}}). I assume that calling {{currentNode.title}}
tries various methods that take a String argument (i.e. "title"), among them
{{Node#getNodes(String)}}. And as you noticed this method is not supported by
the FS resource provider's JCR emulation layer.
Now I see multiple options:
# you provide a pull request to enhance the FS resource provider implementation
# you write ESP scripts using the more verbose {{currentNode.properties.*}}
syntax (or better {{resource.properties.*}}
# you use JCR backed resources rather than FS resources
# you use a modern templating language like Thymeleaf or HTL, possibly with
Sling Models
# you use JSP, also possibly with Sling Models
I would recommend option 4, as that's the most state-of-the-art way of
implementing rendering scripts. Option 5 can be faster to hack, but it tends to
be less maintainable.
> Unable to resolve ESP scripts loaded from Filesystem Resource Provider
> ----------------------------------------------------------------------
>
> Key: SLING-8562
> URL: https://issues.apache.org/jira/browse/SLING-8562
> Project: Sling
> Issue Type: Bug
> Affects Versions: Scripting Core 2.0.46, File System Resource Provider
> 2.1.16
> Reporter: Ben Fortuna
> Priority: Major
>
> A simple test fails when trying to load a resource via Sling Filesystem
> Resource Provider.
> /content/sample/index.json:
> {code:java}
> {
> "sling:resourceType": "sample/page/index",
> "jcr:primaryType": "nt:unstructured",
> "title": "Sample App"
> }{code}
>
> /apps/sample/page/index/html.esp:
> {code:java}
> <html>
> <head><title>${currentNode.title}</title></head>
> <body></body>
> </html>{code}
>
> When both content and app are mounted via Filesystem Resource Provider config
> the following error results:
> {code:java}
> Internal Server Error (500)
> Exception:
> java.lang.UnsupportedOperationException
> at
> org.apache.sling.fsprovider.internal.mapper.jcr.FsNode.getNodes(FsNode.java:517)
> at
> org.apache.sling.scripting.javascript.wrapper.ScriptableNode.get(ScriptableNode.java:319)
> ...{code}
>
> Basically the javascript renderer tries to call `Node.getNodes(pattern)` to
> resolve the property `currentNode.title` but Filesystem Resource Provider
> doesnt support this method.
>
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)