Hi Dennis,

A relatively simple solution is the following:

(1) modify the application sheet to include the following HTML at the end:

<div class="hidden">
  <input type="hidden" name="xredirect" value="$doc.getURL('view',
'sheet=Path.To.NameManager')" />

The result is that whenever you create a new application entry or when you
edit an existing application entry, after you click "Save and view" you
will be taken to the view mode with ?sheet=Path.To.NameManager in the URL
query string, which means the Path.To.NameManager sheet will be applied to
the saved document.

(2) Create the Path.To.NameManager page that determines the right name for
the current document (based on its fields) and renames the current document
if needed ( using the refactoring API
http://extensions.xwiki.org/xwiki/bin/view/Extension/Refactoring+Module ),
finally redirecting to the view mode of the renamed document.

The problem with this solution is that it doesn't work if you use Save &
Continue and then Cancel (I think, to be checked).

Another option, more complex, is to write an event listener that catches
the document save event and renames the document if needed based on its
fields. The bad part with this is that the user is still not redirected
when using Save & Continue.

Hope this helps,

On Mon, Feb 27, 2017 at 3:52 PM, D R <rir....@gmail.com> wrote:

> Hi,
> In an XWiki Application I created I want to make sure documents created
> within it get named in a specific pattern from the fields filled inside
> them.
> Currently I use a custom button to redirect the user to a new document with
> a dummy name so he doesn't need to fill the name (that should get
> overwritten anyway on saving) but only the relevant fields.
> Something like
> #set ( $createDocLink = $xwiki.getURL($document, 'inline',
> "template=${escapetool.url($urlTemplate)}&parent=${
> escapetool.url($urlParent)}&title=${escapetool.url($urlTitle)}")
> )
> This leads to a new document as defined in the application sheet with the
> name 'New document'.
> Now I want the user to fill 3 fields ('freetext1', 'freetext2',
> 'dropdown1'), click 'Save & View' or a custom button. Then the document
> should be saved as '<freetext1> - <freetext2> (<dropdown1>)' and the user
> should be redirected to that page in view mode.
> I've tried different approaches including a temporary creation page with
> the 3 fields as HTML input fields (can't use the applications dropdown),
> event listeners (the redirect after saving doesn't work) ...
> Additionally the same must be done when a page is edited (one of the 3
> fields is changed).
> Please help me find a sane approach before I bite the table.
> Regs, Dennis

Reply via email to