Re: [xwiki-users] Data-Types in UIExtension parameters
On 18 Jan 2016 at 11:15:44, Gerritjan Koekkoek ([email protected](mailto:[email protected])) wrote:
Could I do this in the params:
label=abc
target=Sandbox.try2
icon=gerritjan.png
test=$stringtool.split("item1, item2, item3", “ ,”)
I tried to test it, but did not work?
It won’t work because the parameter values are not typed, they are strings. So if you have: #foreach ($uix in $services.uix.getExtensions(…)) #set ($params = $uix.parameters) ... #end then $params is always a String. Thanks -Vincent PS: Please always reply to the list ;)
The velocity part was:
#set($items=$extension.getParameters().get('test'))
Gerritjan Koekkoek Vader van Rai Koekkoek (cdls) en voorzitter vereniging CdLS Visit our website(http://www.cdlsworld.org) Facebook(https://www.facebook.com/gerritjan.koekkoek) email([email protected])
From: Vincent Massol on behalf of [email protected] Sent: 18 January 2016 10:46 To: XWiki Users Cc: Gerritjan Koekkoek Subject: Re: [xwiki-users] Data-Types in UIExtension parameters
Hi Gerritjan,
On 18 Jan 2016 at 09:34:22, Gerritjan Koekkoek ([email protected](mailto:[email protected])) wrote:
Hi
I wonder if it is possible to use velocity data-types (Number, Date/Time, Array or List, Object) in the parameters field of a UIExtension.
I get the impression it is always considered as string and we have to do a conversion?
I’ve updated the UIX Module documentation at http://extensions.xwiki.org/xwiki/bin/view/Extension/UIExtension+Module#HMor...
So yes, the parameters field can contain velocity.
Following example (for a List of items in a Array)
cdls.try.abc has the following parameters:
label=abc
target=Sandbox.try2
icon=gerritjan.png
test=["Item1", 'item2', "item3"]
{{velocity}}
$services.uix.getExtensions("cdls.try.abc")
#foreach ($extension in $services.uix.getExtensions("cdls.try.abc"))
$services.rendering.render($extension.execute(), 'xhtml/1.0')
#set($paramlist=$extension.getParameters().get('test'))
#end
paramlist is String?: $paramlist.class
##Would like it to be a list of items, but now I have to use velocity string functions to create the list...
#set($paramlistLengthMinusOne = $paramlist.length() - 1)
#set($items = $paramlist.substring(1, $paramlistLengthMinusOne).split(","))
#foreach($item in $items)
[snip]
That’s correct, UIX parameters are not typed (they’re strings).
However you can simplify a lot your velocity code.
In the UIX: test=item1, item2, item3
In the calling code: #set ($paramlist = $extension.getParameters().get('test')) #set ($items = $stringtool.split($paramList, “ ,”)) …
Thanks -Vincent
Gerritjan Koekkoek Vader van Rai Koekkoek (cdls) en voorzitter vereniging CdLS
participants (1)
-
vincent@massol.net