[
https://issues.apache.org/jira/browse/SLING-533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12605625#action_12605625
]
Alexander Klimetschek commented on SLING-533:
---------------------------------------------
Would be cool if the documentation on Sling's website could be updated to
reflect the new TypeHint multivalue capabilities:
http://incubator.apache.org/sling/site/[EMAIL PROTECTED]
respectively on the site source wiki
http://cwiki.apache.org/confluence/display/SLINGxSITE/Manipulating+Content+-+The+SlingPostServlet
Here is my replacement for the @TypeHint section.
[doc] -----
Parameters with the @TypeHint suffix may be used to force storing the named
parameter in a property with the given type. The value of the @TypeHint
parameter if applied to a parameter for a property is the JCR property type
name. If the @TypeHint parameter is applied to a field upload parameter, the
value is used to indicate the JCR primary node type for the node into which the
uploaded file is stored.
If the TypeHint ends with "[]", it indicates a multi-value property. A
multi-value property is normally auto-detected if there are multiple values for
the property (ie. request parameter). But if only a single value is present in
the request, the desired property type needs to be explicitly defined by
stating @TypeHint=<type>[].
Example: The following form sets the numeric width, the boolean checked and the
multi-valued hobbys (with 3 values to enter) properties:
<form method="POST" action="/content/page/first">
<input type="text" name="width" />
<input type="hidden" name="[EMAIL PROTECTED]" value="Long" />
<input type="checkbox" name="checked" />
<input type="hidden" name="[EMAIL PROTECTED]" value="Boolean" />
<input type="text" name="hobbys" />
<input type="text" name="hobbys" />
<input type="text" name="hobbys" />
<input type="hidden" name="[EMAIL PROTECTED]" value="String[]" />
<input type="Submit" />
</form>
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 [EMAIL PROTECTED] would be the
same.
[/doc] -----
> Support multi-value type hints (eg. @TypeHint=String[])
> -------------------------------------------------------
>
> Key: SLING-533
> URL: https://issues.apache.org/jira/browse/SLING-533
> Project: Sling
> Issue Type: New Feature
> Components: Servlets Post
> Reporter: Alexander Klimetschek
> Assignee: Carsten Ziegeler
> Fix For: 2.0.1
>
> Attachments: multival-post-test.html
>
>
> As discussed in SLING-522, when posting a single value to a property that
> should be multi-valued, an extension to the @TypeHint is needed that allows
> the explicit definition of a multi-value type. For example, for Strings this
> would be @TypeHint=String[].
> Based on a quick look at the code, it should happen in
> o.a.s.servlets.post.impl.helper.SlingPropertyValueHandler.setPropertyAsIs().
> First of all the parsing of the getTypeHint() must be changed to look for an
> ending [] first, and then this "isMultiValued" information must be used to
> call the multi-value version of setProperty() in all cases (values.length >=
> 0).
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.