[jira] Created: (SLING-657) inconsistent date behaviour of sling.wizard()

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (SLING-657) inconsistent date behaviour of sling.wizard()

Robert Munteanu (Jira)
inconsistent date behaviour of sling.wizard()
---------------------------------------------

                 Key: SLING-657
                 URL: https://issues.apache.org/jira/browse/SLING-657
             Project: Sling
          Issue Type: Bug
          Components: Scripting
         Environment: Sling bundled with CRX Quickstart
            Reporter: Michael Marth


I create a form in a .jst page that creates a new node and add the special "craeted" field like this:

                                        <form class="hform" method="POST" action="/content/myblog/posts/*">
                  <legend>Post form</legend>
                                                       
                                                                <p><label>Title</label>
                                                                <input name="title" type="text" size="80"></p>
                                                               
                                                                <p><label>Body</label>
                                                                <textarea name="posttext" cols="40" rows="5"></textarea></p>
                                                               
                                                                <input type="hidden" name="created"/>
                                                                <input name=":redirect" type="hidden" value="/content/myblog/posts.admin.html"/>
                                                                                                       
                                                <input type="submit" value="Post" class="button">
                                        </form>
                                        <script>Sling.wizard();</script>

This will create the node with an attribute "created" of JCR type Date

Then, I use the same .jst to edit this node and post again. This time, "created" will be a String property.

Causes other scripts that use this property to fail

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (SLING-657) inconsistent date behaviour of sling.wizard()

Robert Munteanu (Jira)

    [ https://issues.apache.org/jira/browse/SLING-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12631019#action_12631019 ]

Bertrand Delacretaz commented on SLING-657:
-------------------------------------------

I think the problem lies in the SlingPropertyValueHandler class:

    public void setProperty(Node parent, RequestProperty prop)
...
        final String name = prop.getName();
        if (prop.providesValue()) {
            // if user provided a value, don't mess with it
            setPropertyAsIs(parent, prop);

        } else if (AUTO_PROPS.containsKey(name)) {
...

So, if an "auto property" provides a value, that is used as is by the post servlet.

If if didn''t do that, all the AUTO_PROPS names (created, lastModified, etc.) would be reserved for sling's purposes.

That's what happens when a form handled by the sling wizard is posted, the "created" field contains the string representation of the property value.

To avoid this, the sling wizard could make sure those properties are emptied before posting the request, not optimal but simple to implement. If we do this, sling.js should at least query the Sling server for the list of names for these properties, so as to avoid having to define the list in two places.

Another way might be to use names prefixed by "sling:" for those automatic properties, and reserve this prefix for properties set by Sling.

Not sure how to best solve that...

> inconsistent date behaviour of sling.wizard()
> ---------------------------------------------
>
>                 Key: SLING-657
>                 URL: https://issues.apache.org/jira/browse/SLING-657
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>         Environment: Sling bundled with CRX Quickstart
>            Reporter: Michael Marth
>
> I create a form in a .jst page that creates a new node and add the special "craeted" field like this:
> <form class="hform" method="POST" action="/content/myblog/posts/*">
>           <legend>Post form</legend>
>
> <p><label>Title</label>
> <input name="title" type="text" size="80"></p>
>
> <p><label>Body</label>
> <textarea name="posttext" cols="40" rows="5"></textarea></p>
>
> <input type="hidden" name="created"/>
> <input name=":redirect" type="hidden" value="/content/myblog/posts.admin.html"/>
>
> <input type="submit" value="Post" class="button">
> </form>
> <script>Sling.wizard();</script>
> This will create the node with an attribute "created" of JCR type Date
> Then, I use the same .jst to edit this node and post again. This time, "created" will be a String property.
> Causes other scripts that use this property to fail

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.