incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject svn commit: r1565846 - /sling/site/trunk/content/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.mdtext
Date Fri, 07 Feb 2014 23:12:25 GMT
Author: rombert
Date: Fri Feb  7 23:12:25 2014
New Revision: 1565846

SLING-2393 - Update Post Servlet Documentation for patch operation

Applied patch from Alexander Klimetschek.


Modified: sling/site/trunk/content/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.mdtext
--- sling/site/trunk/content/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.mdtext
+++ sling/site/trunk/content/documentation/bundles/manipulating-content-the-slingpostservlet-servlets-post.mdtext
Fri Feb  7 23:12:25 2014
@@ -266,6 +266,8 @@ Example: The following form sets the num
 In real applications you would need some javascript that allows to add/remove values, ie.
add/remove inputs with the name "hobbys". Or a pure javascript based form post would be used,
that gathers the properties to update programmatically, but the additional parameter `hobbys@TypeHint=String[]`
would be the same.
 The `@TypeHint` suffixed parameter is assumed to be single-valued. If the parameter has multiple
values, only the first is actually used.
+For multi-value properties, see also the `@Patch` option.
 For more information on applying `@TypeHint` to a file upload parameter see the section on
File Uploads above.
@@ -420,8 +422,33 @@ The `@CopyFrom` suffixed parameter is as
 The `@CopyFrom` suffixed parameter is also special in that there must not be a correlated
parameter without a suffix. Thus have parameters `text` and `text@CopyFrom` may have unexpected
-The `@CopyFrom` suffixed parameter in fact calls for a sub-operation, which is executed after
the `@MoveFrom` sub operation but before any other tasks of content creattion and modification
are done.
+The `@CopyFrom` suffixed parameter in fact calls for a sub-operation, which is executed after
the `@MoveFrom` sub operation but before any other tasks of content creation and modification
are done.
+###### `@Patch`
+When modifying multi-value properties, the `@Patch` suffix can be used to just add `+` or
remove `-` individual values without overwriting the full array. This allows to change the
array without knowing the current values.
+For example, imagine a multi-value string property that stores tags or keywords. To both
add a tag "cool" and remove "boring" from the list:
+    <form method="POST" action="/content/page/first" enctype="multipart/form-data">
+        <input type="hidden" name="tags@TypeHint" value="String[]" />
+        <input type="hidden" name="tags@Patch"    value="true" />
+        <input type="text"   name="tags"          value="+cool"/>
+        <input type="text"   name="tags"          value="-boring"/>
+        <input type="Submit" />
+    </form>
+The array will be treated like a set: when adding a value, it will only be added once if
it does not exist yet; when removing a value, all occurences of it will be removed. For values
not affected by the add or remove operations, nothing changes. An existing array with duplicate
entries will not automatically be converted into a set.
+The format for an individual parameter value is `<operation><value>`. If there
is no or no valid operation given, this value will be ignored.
+Operation `+` will add the `<value>` to the array if it is not part of it yet.
+Operation `-` will remove all occurences of `<value>` from the array.
+The value of the `@Patch` suffixed parameter is irrelevant, it can be empty (example above
uses `true` for clarity).
+All types should be supported via `@TypeHint`, but it needs to indicate a multi-value property,
ending with `[]`.
 ##### Algorithm for Node Name Creation

View raw message