You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Bertrand Delacretaz <bd...@apache.org> on 2008/01/24 14:19:02 UTC

SLING-154, ScriptableNode access to Properties and JCR methods, how?

Hi,

Before SLING-154, the javascript expression "node.text" (in ESP
scripts for example) would return the JCR "text" property of the node.

I assume this is the most frequent use case for scripted Nodes: work
with their content, so we should make this as natural as possible, for
example:

  node.text -> value of the "text" property of the node
  node.children.foo -> the "foo" child node

Now, we'd like to call JCR methods on the Node object as well - but if
we represent JCR getters as javascript properties, like

  node.path -> call JCR Node.getPath()

We get a name collision with a Property that would be called "path".

Any ideas on how to best solve this?

The simplest way might be to require the use of node.getPath() instead
of node.path, and use javascript property names for content access
only, not for JCR getters.

-Bertrand

Re: SLING-154, ScriptableNode access to Properties and JCR methods, how?

Posted by David Nuescheler <da...@day.com>.
> Node methods are accessible in javascript with their real names like
> "node.getPath()".
very cool.

> Node poperties and child nodes are accessible as javascript
> properties, like "node.text".
sounds great.

> On Feb 1, 2008 8:01 PM, Felix Meschberger <fm...@gmail.com> wrote:
> > ...I am perfectly fine going back to not having the methods be
> > properties and access properties and child nodes as properties of the
> > node - which is equally natural, of course. But then, we should finally
> > keep it one way or the other, ok ?...
> Sure, I think the current status is usable, and direct access to JCR
> methods allows edge cases to be solved, if needed.
sounds excellent, exactly what i was looking for...

i especially like this approach since it allows for a similar access to
content in client sided ujax.

regards,
david

Re: SLING-154, ScriptableNode access to Properties and JCR methods, how?

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

I just committed changes to resolve SLING-154.

Node methods are accessible in javascript with their real names like
"node.getPath()".

Node poperties and child nodes are accessible as javascript
properties, like "node.text".

On Feb 1, 2008 8:01 PM, Felix Meschberger <fm...@gmail.com> wrote:

> ...I am perfectly fine going back to not having the methods be
> properties and access properties and child nodes as properties of the
> node - which is equally natural, of course. But then, we should finally
> keep it one way or the other, ok ?...

Sure, I think the current status is usable, and direct access to JCR
methods allows edge cases to be solved, if needed.

-Bertrand

Re: SLING-154, ScriptableNode access to Properties and JCR methods, how?

Posted by Felix Meschberger <fm...@gmail.com>.
Hi all,

You know, I don't really care what we do (here). But, we should not
start discussing this over and over. Once we decided it would be a good
idea to do the mapping the JavaScript way, that is getters are turned
into (read-only) properties. To prevent the collisions, that Bertrand
mentioned, we agreed to insert synthetic objects (properties, children).

Now, I am perfectly fine going back to not having the methods be
properties and access properties and child nodes as properties of the
node - which is equally natural, of course. But then, we should finally
keep it one way or the other, ok ?

BTW: If a node has a child node and property with the same name, the
node is returned and not the property. And of course, this mechanism
will most probably not easily support SNS, which should not be used
anyway ;-)

What do others thinkg ?

Regards
Felix


Am Freitag, den 01.02.2008, 15:27 +0100 schrieb David Nuescheler:
> Hi Bertrand,
> 
> > The simplest way might be to require the use of node.getPath() instead
> > of node.path, and use javascript property names for content access
> > only, not for JCR getters.
> I completely agree to that solution.
> 
> I think I have a strong bias for using node.propname for accessing the
> properties
> and the node.childnodename for child nodes.
> 
> One of the reasons to resolve the issue this way is that this would allow
> compatibility between ujax (jst) and .esp when it comes to content access.
> 
> (especially if we would introduce a currentNode on the server side aswell)
> 
> I think accessing the original Node methods with node.getPath, node.getSession()
> is perfectly acceptable.
> 
> regards,
> david


Re: SLING-154, ScriptableNode access to Properties and JCR methods, how?

Posted by David Nuescheler <da...@day.com>.
Hi Bertrand,

> The simplest way might be to require the use of node.getPath() instead
> of node.path, and use javascript property names for content access
> only, not for JCR getters.
I completely agree to that solution.

I think I have a strong bias for using node.propname for accessing the
properties
and the node.childnodename for child nodes.

One of the reasons to resolve the issue this way is that this would allow
compatibility between ujax (jst) and .esp when it comes to content access.

(especially if we would introduce a currentNode on the server side aswell)

I think accessing the original Node methods with node.getPath, node.getSession()
is perfectly acceptable.

regards,
david