Thanks Ludovic, $xwiki.getUniquePageName is excellent!
The only 'hack' I still have to make is generating empty pages '2010',
'2011', '2012', '2013' so there won't be a page created with
that
name.
For those interested in the outcome:
{{velocity}}
##configure these variables
#set($space="Sandbox2")
#set($template="AppSpace.DemoTemplate")
#set(#editmode="edit") ##either 'edit' or 'inline', depending on
the template
##end configurable values
#set($parent=$space+".WebHome")
#set($year= ${xwiki.formatDate($datetool.date, 'yyyy')})
#set($year=${request.year}) ##could have been 'if !$year -> set from
system time, but this won't overrule
#set($docname=$xwiki.getUniquePageName($space , $year))
#if(!$xwiki.exists($docname) && $xwiki.hasAccessLevel('edit',
$context.user, $docname))
$response.sendRedirect($xwiki.getURL($docname, $editmode,
"template=$template&parent=$parent"))
## Stop processing, since we already sent a redirect.
#stop
#end
{{/velocity}}
On Wed, Jan 11, 2012 at 9:34 PM, Ludovic Dubost <ludovic(a)xwiki.com> wrote:
Joris,
There is the $xwiki.getUniquePageName("SpaceName" , "BasePageName")
which
allows to give you a page name not existing in XWiki.
It works in most cases, except if you generate the page name before the
save (for the form display) as you risk having twice the same name.
If you make this call just before the save, the duplicate risks are close
to zero.
As Edo has mentionned, a component would be needed to guarantee zero
possible duplication and/or to generate the page name for the edit form
(before saving). An even there there are some issues to support clustering.
We have been thinking about this and is part of our plan for 3.4/3.5 or
early 4.0.
Ludovic
2012/1/11 Joris Dirks <joris(a)user.stekje.nl>
One of the use cases I have for my wiki is
storing 'issues', where
each issue should have a serial number consisting of year + subsequent
number.
I was thinking about a script like this, but one of the problems is:
there is no 'while' function in Velocity.
How would you create a form for this? Thanks for your ideas!
Joris
#set($space="Issues"}
#set($template="AppSpace.IssueTemplate")
#set($parent=$space.WebHome)
#set($year= ${xwiki.formatDate($datetool.date, 'yyyy')})
#set($partID="0"
#set($genericID=$space"."$year)
#while($xwiki.exists($space.$issueID'')
{
#set($partID=$partID+1)
#set($issueID=$year"-"$partID)
}
#if(!$xwiki.exists($issueID) && $xwiki.hasAccessLevel('edit',
$context.user, $issueID))
$response.sendRedirect($xwiki.getURL($ID, 'inline',
"template=$template}&parent=$parent"))
## Stop processing, since we already sent a redirect.
#stop
#end
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users
--
Ludovic Dubost
Founder and CEO
Blog:
http://blog.ludovic.org/
XWiki:
http://www.xwiki.com
Skype: ldubost GTalk: ldubost
_______________________________________________
users mailing list
users(a)xwiki.org
http://lists.xwiki.org/mailman/listinfo/users