Hi Marius,

the refactoring approach sounds great but there seems to be something I do
wrong because the renaming doesn't work. Maybe I misunderstood the term
"current document" but I'm not sure.

I created "Test App.Code.Test App NameManager" with the following content:

```
{{velocity}}
#set ($renameRequest =
$services.refactoring.createRenameRequest($doc.fullName, 'Now RENAMED'))
#set ($discard = $renameRequest.setAutoRedirect(false))
$services.refactoring.rename($renameRequest)).join()
{{/velocity}}

```

Then I put your DIV at the end of my app sheet:

```
{{velocity}}
{{html wiki="true"}}
#set ($discard = $doc.use('Test App.Code.Test AppClass'))
(% class="xform" %)
(((
   [FORM CONTENT]
)))

<div class="hidden">
  <input type="hidden" name="xredirect" value="$doc.getURL('view',
"sheet=${escapetool.url('Test App.Code.Test App NameManager')}")" />
</div>

{{/html}}
{{/velocity}}

```

Then I opened up one of the application entries, edited it and hit "Save
and view" but the name didn't change.

Could you please tell me what I did wrong.

Thanks in advance,
Dennis

2017-02-28 11:38 GMT+01:00 Marius Dumitru Florea <
mariusdumitru.flo...@xwiki.com>:

> 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')" />
> </div>
>
> 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,
> Marius
>
> 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