I create
MyClass/Sheet/Template and in
another AnotherClass I add a Page type property
with:
- Display Type : select
- XWiki Class Name: MyClass
- Id Field Name: doc.fullName
- Value Field Name : doc.name
My purpose is to
display a list of page (with MyClass object): this point is
working well but ...
I want that the user
select in my select
list: one page OR nothing.
...
in
order to add this item to a Page
(actually DatabaseList) property you
have to
write a custom displayer. Another solution may be to create
Here I created a nice custom displayer in MyClass: Property type: Page (or database
list)
It's filtered hidden doc and add one Empty entry in select list.
- Display Type : select
Hibernate Query (to filter hidden doc because
http://jira.xwiki.org/browse/XWIKI-12031
issue): select distinct doc.name from XWikiDocument as doc, BaseObject as obj where
doc.fullName=obj.name and obj.className='FormSMQ.EAClass' and
doc.space='FormSMQ' and doc.hidden=false
Custom Display:
{{velocity}}
#if ($type == 'edit')
#set($MyClass=$object.getxWikiClass())
#set($list=$MyClass.get($name).getListValues())
#set ($MySelectList="<select id='" + "${prefix}_${name}" +
"' size='1' name='" + $prefix + ${name} +
"'>")
#set ($Selected="")
#if ($!value=='')
#set ($Selected=" selected='selected'")
#end
#set ($MySelectList=$MySelectList + "<option value=''" + $!Selected
+ " label='" +
$services.localization.render('FormSMQ.PiacJ2Class.Empty') + "'>"
+ $services.localization.render('FormSMQ.PiacJ2Class.Empty') +
"</option>")
#foreach($listitem in $list)
#if ($listitem==$value)
#set ($Selected=" selected='selected'")
#else
#set ($Selected="")
#end
#set ($MySelectList=$MySelectList + "<option value='" + $listitem +
"'" + $!Selected + " label='" + $listitem +
"'>" + $listitem + "</option>")
#end
#set ($MySelectList=$MySelectList + "</select>")
#set ($MySelectList=$MySelectList + "<input type='hidden'
value='' name='" + ${prefix} + ${name} +"'>")
{{html clean=false}}
$MySelectList
{{/html}}
#elseif (($type == 'view') && ($!value!=''))
[[$value]]
#else
$value
#end
{{/velocity}}
Use $object.getxWikiClass().get($name).getMapValues() with XWiki Class Name: MyClass +Id
Field Name: doc.fullName + Value Field Name : doc.name
First I used this awfull code (to forget of course):
#if ($type == 'edit')
#set ($propertyClass = $object.getxWikiClass().get($name))
#set ($MySelectList = $doc.displayEdit($propertyClass, $prefix, $object))
#set ($Empty=$services.localization.render('FormSMQ.PiacJ2Class.Empty'))
#if ($!value!='')
## if not empty, add "Empty" "option value"
#set($EmptyValueAdded='<option value="" label=' + $Empty +
'>' + $Empty + '</option><option value=')
#set ($MySelectList = $stringtool.replaceOnce($MySelectList, '<option
value=', $EmptyValueAdded))
#else
## if empty, add SELECTED "Empty" "option value"
#set($EmptyValueAdded="<option selected='selected' value=''
label='" + $Empty + "'>" + $Empty +
"</option>")
#set ($MySelectList = $stringtool.replaceOnce($MySelectList, "<option
selected='selected' value='' label=''></option>",
$EmptyValueAdded))
#end
Thxs for your help.
Pascal B