You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Gilles Scokart <gs...@gmail.com> on 2008/07/19 17:14:15 UTC
Playing with multiple nodes
I'm new to Sling, but I like very much what I have seen up to now.
There is however one thing that I didn't managed to understand yet :
How can we play with multiple nodes : list of nodes, queries, filters
or node coming from 2 completely different path
--
Gilles Scokart
Re: Playing with multiple nodes
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Tue, Jul 22, 2008 at 1:31 PM, Gilles Scokart <gs...@gmail.com> wrote:
> ...Following the Lars cheatsheet, I would have expected to have the step
> 2 (content resolution) being able to handle queries, and then having
> step 3 deriving a nice ressource type (employee/list for instance)
> followed then by normal rendering steps....
That sounds interesting, but given the following structure, how do you
decide which resource should map to a query and which should not?
employee
+ bob
+ firstname
+ lastname
Is employee.html meant to be a query? What about employee/bob.html?
I'm not sure if there is a general rule that can be used for that.
Now, in your case, if you set sling:resourceType=employee/list on the
employee node, you can map that to a script or servlet that executes a
query, something like /employee.html?name=bob*&offset=2...
What might be interesting is to create a generic servlet for such use
cases, and map that to a sling/query resource type for example. Query
result renderers for different extensions could then be created, and
the existing json query servlet would be one of those.
-Bertrand
Re: Playing with multiple nodes
Posted by Felix Meschberger <fm...@gmail.com>.
Hi Gilles,
The paradigm of Sling is, that the request URL resolves to a single
Resource, which is usually backed by a single JCR node. The Resource has
a so-called resource type (comparable to a Java Class) which is used to
select the script to call (similar to method selection in Java) [ When
comparing to Java the Resource would then actually be something like the
instance of the class ].
So if you have your employees stored under /location/employees. You
might request /location/employees.infinity.json and get back a JSON
rendering of the subtree below /location/employees (in the AJAX case).
Alternatively you might provide a rendering script the resource type of
the /location/employees node which returns an HTML table of the employees.
Hope this helps.
Regards
Felix
Gilles Scokart schrieb:
> That's very good. It means that out of the box sling support lists of nodes.
>
> However, I have the feeling that the approach is not consistent with
> the processing of a simple resource.
>
> Following the Lars cheatsheet, I would have expected to have the step
> 2 (content resolution) being able to handle queries, and then having
> step 3 deriving a nice ressource type (employee/list for instance)
> followed then by normal rendering steps.
>
> That would allow for instance to have list rendered into xml of html,
> and not only json. And moreover, I feel that would have made the
> model more consistent.
>
> Is my point of view correct, or did I have the wrong paradigm glasses?
>
> My jcr-foo is too limited to say if such approach would be possible,
> and if it is it will certainly require some magic. But when I look at
> sling, it is what I see : 'Magic'.
>
>
> Gilles Scokart
>
>
> 2008/7/21 Bertrand Delacretaz <bd...@apache.org>:
>> On Sat, Jul 19, 2008 at 7:31 PM, Gilles Scokart <gs...@gmail.com> wrote:
>>
>>> ...But what If I want to list all employees in a page or as a result of
>>> an AJAX call? Did I have to use the url of the parent node of all the
>>> employee and map that to a rendering script that I have to write ? Is
>>> there any default rendering for list ?...
>> The json rendering is recursive, so if you have a node
>> /content/employees that contains many employee nodes, you can list
>> them all at once by requesting /content/employees.infinity.json, or
>> /content/employees.2.json if you want only 2 levels, etc.
>>
>>> ...And what if I only want a sublist (as a result of a query for instance) ?...
>> Then yes you'll need a query - the simplest way is to use the
>> JsonQueryServlet which you'd call for example like
>>
>> /content/employees.query.json?statement=...&queryType=...&offset=10&rows=10
>>
>> See JsonQueryServletTest [1] for (a few) examples. The offset/rows
>> parameters are used for paging through results.
>>
>> -Bertrand
>>
>> [1] http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonQueryServletTest.java
>>
>
Re: Playing with multiple nodes
Posted by Gilles Scokart <gs...@gmail.com>.
That's very good. It means that out of the box sling support lists of nodes.
However, I have the feeling that the approach is not consistent with
the processing of a simple resource.
Following the Lars cheatsheet, I would have expected to have the step
2 (content resolution) being able to handle queries, and then having
step 3 deriving a nice ressource type (employee/list for instance)
followed then by normal rendering steps.
That would allow for instance to have list rendered into xml of html,
and not only json. And moreover, I feel that would have made the
model more consistent.
Is my point of view correct, or did I have the wrong paradigm glasses?
My jcr-foo is too limited to say if such approach would be possible,
and if it is it will certainly require some magic. But when I look at
sling, it is what I see : 'Magic'.
Gilles Scokart
2008/7/21 Bertrand Delacretaz <bd...@apache.org>:
> On Sat, Jul 19, 2008 at 7:31 PM, Gilles Scokart <gs...@gmail.com> wrote:
>
>> ...But what If I want to list all employees in a page or as a result of
>> an AJAX call? Did I have to use the url of the parent node of all the
>> employee and map that to a rendering script that I have to write ? Is
>> there any default rendering for list ?...
>
> The json rendering is recursive, so if you have a node
> /content/employees that contains many employee nodes, you can list
> them all at once by requesting /content/employees.infinity.json, or
> /content/employees.2.json if you want only 2 levels, etc.
>
>>
>> ...And what if I only want a sublist (as a result of a query for instance) ?...
>
> Then yes you'll need a query - the simplest way is to use the
> JsonQueryServlet which you'd call for example like
>
> /content/employees.query.json?statement=...&queryType=...&offset=10&rows=10
>
> See JsonQueryServletTest [1] for (a few) examples. The offset/rows
> parameters are used for paging through results.
>
> -Bertrand
>
> [1] http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonQueryServletTest.java
>
Re: Playing with multiple nodes
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Sat, Jul 19, 2008 at 7:31 PM, Gilles Scokart <gs...@gmail.com> wrote:
> ...But what If I want to list all employees in a page or as a result of
> an AJAX call? Did I have to use the url of the parent node of all the
> employee and map that to a rendering script that I have to write ? Is
> there any default rendering for list ?...
The json rendering is recursive, so if you have a node
/content/employees that contains many employee nodes, you can list
them all at once by requesting /content/employees.infinity.json, or
/content/employees.2.json if you want only 2 levels, etc.
>
> ...And what if I only want a sublist (as a result of a query for instance) ?...
Then yes you'll need a query - the simplest way is to use the
JsonQueryServlet which you'd call for example like
/content/employees.query.json?statement=...&queryType=...&offset=10&rows=10
See JsonQueryServletTest [1] for (a few) examples. The offset/rows
parameters are used for paging through results.
-Bertrand
[1] http://svn.eu.apache.org/repos/asf/incubator/sling/trunk/launchpad/webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonQueryServletTest.java
Re: Playing with multiple nodes
Posted by Alexander Klimetschek <ak...@day.com>.
Inside a servlet or script you can do whatever you want - you are not
restricted to the currentNode you get. For example, you can
- iterate over the child nodes and list them
- use the resource resolver to get any node in the repository, do queries etc.
- you can also get the JCR session
(resourceResolver.adaptTo(Session.class)) directly, if you know you
only work on the JCR repository - this gives you complete access to
the JCR API
- use sling.include() to include a different path (as Bertrand noted already)
Regards,
Alex
On Sat, Jul 19, 2008 at 7:31 PM, Gilles Scokart <gs...@gmail.com> wrote:
> Maybe I don't have the right paradigm. Here is what I would expect to
> be able to do (with my limited knowledge of sling).
>
> Imagine that I have a resources type 'employee'.
>
> I have understood that with a particular URL, sling will resolve it
> and find a particular employee node and will give this node to an ESP,
> a JSP or a servlet that will render it.
>
> That's nice if I want to see all the properties of a single employee on my page.
>
> But what If I want to list all employees in a page or as a result of
> an AJAX call? Did I have to use the url of the parent node of all the
> employee and map that to a rendering script that I have to write ? Is
> there any default rendering for list ?
>
> And what if I only want a sublist (as a result of a query for instance) ?
>
>
>
>
> 2008/7/19 Bertrand Delacretaz <bd...@apache.org>:
>> Hi,
>>
>> On Sat, Jul 19, 2008 at 5:14 PM, Gilles Scokart <gs...@gmail.com> wrote:
>>> ...How can we play with multiple nodes : list of nodes, queries, filters
>>> or node coming from 2 completely different path...
>>
>> Not sure what you mean by that - a Sling script can include the
>> rendering of other nodes by using the include function, for example in
>> ESP:
>>
>> sling.include("/content/foo.html")
>>
>> And that has some options such as forcing a specific resource type,
>> for example to render the current node using a different rendering
>> script for navigation.
>>
>> Does that help? If not, please give more details as to what you're
>> trying to achieve.
>>
>> -Bertrand
>>
>
>
>
> --
> Gilles Scokart
>
--
Alexander Klimetschek
alexander.klimetschek@day.com
Re: Playing with multiple nodes
Posted by Gilles Scokart <gs...@gmail.com>.
Maybe I don't have the right paradigm. Here is what I would expect to
be able to do (with my limited knowledge of sling).
Imagine that I have a resources type 'employee'.
I have understood that with a particular URL, sling will resolve it
and find a particular employee node and will give this node to an ESP,
a JSP or a servlet that will render it.
That's nice if I want to see all the properties of a single employee on my page.
But what If I want to list all employees in a page or as a result of
an AJAX call? Did I have to use the url of the parent node of all the
employee and map that to a rendering script that I have to write ? Is
there any default rendering for list ?
And what if I only want a sublist (as a result of a query for instance) ?
2008/7/19 Bertrand Delacretaz <bd...@apache.org>:
> Hi,
>
> On Sat, Jul 19, 2008 at 5:14 PM, Gilles Scokart <gs...@gmail.com> wrote:
>> ...How can we play with multiple nodes : list of nodes, queries, filters
>> or node coming from 2 completely different path...
>
> Not sure what you mean by that - a Sling script can include the
> rendering of other nodes by using the include function, for example in
> ESP:
>
> sling.include("/content/foo.html")
>
> And that has some options such as forcing a specific resource type,
> for example to render the current node using a different rendering
> script for navigation.
>
> Does that help? If not, please give more details as to what you're
> trying to achieve.
>
> -Bertrand
>
--
Gilles Scokart
Re: Playing with multiple nodes
Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,
On Sat, Jul 19, 2008 at 5:14 PM, Gilles Scokart <gs...@gmail.com> wrote:
> ...How can we play with multiple nodes : list of nodes, queries, filters
> or node coming from 2 completely different path...
Not sure what you mean by that - a Sling script can include the
rendering of other nodes by using the include function, for example in
ESP:
sling.include("/content/foo.html")
And that has some options such as forcing a specific resource type,
for example to render the current node using a different rendering
script for navigation.
Does that help? If not, please give more details as to what you're
trying to achieve.
-Bertrand