Hi,

As far as I can see, you submit the form to
'/bin/save/FormSMQ/MyCurrentPage' in javascript and *immediately* after the
submit(), you send the redirect to
'FormSMQ/MyCurrentPage?docName=LauchNextProcess'  which adds the object.

IMO, the problem is that you are not making sure that the save operation
triggered by the submit() actually has the time to finish saving and, when
the redirect loads the $doc to add the new object, it loads te $doc that
was in the database before the save operation has the time to change it, so
you end up with the previous version of the $doc to which you just add the
object.

Instead of doing the redirect yourself with window.location, why don`t you
use the 'xredirect' paremeter? You have 2 options, either add it to the URL
in the action of the form (e.g.
'/bin/save/FormSMQ/MyCurrentPage?xredirect=$xwiki.getURL("FormSMQ.CaFonctionneOuPas".....')
or just get the existing hidden input with javascript
(input[name="xredirect"]) and set its value to whatever you want
($xwiki.getURL("FormSMQ.CaFonctionneOuPas".....) before submitting the
form? This way, the save action will redirect you to wherever the xredirect
parameter tells it to and it will do so *after* completing the save
operation in the database.

Hope this helps,
Eduard

On Wed, Oct 7, 2015 at 3:38 PM, Pascal BASTIEN <pbasnews-xw...@yahoo.fr>
wrote:

> Hi,
> I think I found a way to do what i want but I identify some issue
> (probably due to my ugly code)
>
> - my button SaveAndStuff launch this JS
>   $('#inline').attr('action','/bin/save/FormSMQ/MyCurrentPage');
>   // I save my CurrentPage
>   $('#inline').submit();
>   // I reopen my CurrentPage in view mode with param to launch my velocity
> script
>    window.location = "
> https://xxxxxxxxxx/bin/view/FormSMQ/MyCurrentPage?docName=LauchNextProcess";;
> //Open MyCurrentPage with parameters
>
> In FormSMQ/MyCurrentPage I have this velocity script:
> #if("$!request.docName"=='LauchNextProcess'')
>   ## I add a value in a field (list) of MyClass object of currenpage
>   #set($MyListActions=$MonObj.getValue($ListActionsField))
>   #set($Discard=$MyListActions.add("$!MonPrefX${docName}"))
>   #set ($discard=$MonObj.set($ListActionsField,$!MyListActions))
>
>   ## I save my CurrentPage to save my previous new value
>   #set ($discard=$doc.save("Nouvelle action =>
> $!MonPrefX${docName}",false))
>
>   ##Finally I redirect to another page
>   #$response.sendRedirect($xwiki.getURL("FormSMQ.CaFonctionneOuPas",
> 'edit',
> "template=FormSMQ.ACTemplate&parent=FormSMQ.WebHome&title=FormSMQ.CaFonctionneOuPas&TypeFic=FormSMQ.ACClass"))
>       ## Stop processing, since we already sent a redirect.
>       #stop
>
> My problem is: when I use "$doc.save", all modifications of my page are
> lost (except the new value added)!
> If I don't use "$doc.save" all page modifications are saved but of course
> my new value is not added :-(
>
> It is a "bit" confused but if someone understand...
>
> --------------------------------------------
> En date de : Mar 6.10.15, Pascal BASTIEN <pbasnews-xw...@yahoo.fr> a
> écrit :
>
>  Objet: [xwiki-users] Fw : Re: Fw : Re: How to add a button with
> confirmation to save my page?
>  À: "Marius Dumitru Florea" <mariusdumitru.flo...@xwiki.com>
>  Cc: "XWiki Users" <users@xwiki.org>
>  Date: Mardi 6 octobre 2015, 18h22
>
>  I manage to launch save process of my
>  page but I didn't manage to pass parameter in this process
>  :-(
>
>  On my page in edit mode, I add a button with this JS code:
>  function SaveCurrentPage(MyForm, MyParam) {
>    require(['jquery'], function ($) {
>
>
>  
> $('#inline').attr('action','/bin/save/FormSMQ/SMQ-M2-FAM-Mon+am%C3%A9lioration');
>    //$('#inline').attr('method','get');
>    $('#inline').submit();
>    });
>  };
>  this code save current page and go in the view mode BUT I
>  can NOT pass some parameters to my velocity code and update
>  myClass object :-(
>
>  In the other way when I submit to view mode with
>
>  
> $('#inline').attr('action','/bin/view/FormSMQ/SMQ-M2-FAM-Mon+am%C3%A9lioration');
>  My current page is NOT saved but I can pass some parameter
>  with hidden input (I can catch them with $request.aaaa in
>  velocity code)
>
>
>
>
>  --- En date de : Mar 6.10.15, Marius Dumitru Florea <
> mariusdumitru.flo...@xwiki.com>
>  a écrit :
>
>  > De: Marius Dumitru Florea <mariusdumitru.flo...@xwiki.com>
>  > Objet: Re: [xwiki-users] Fw : Re: How to add a button
>  with confirmation to save my page?
>  > À: "XWiki Users" <users@xwiki.org>
>  > Date: Mardi 6 octobre 2015, 12h23
>  > On Tue, Oct 6, 2015 at
>  > 1:01 PM, Pascal BASTIEN <pbasnews-xw...@yahoo.fr>
>  > wrote:
>  > > First thxs both  but it is not
>  > what I want try to do.
>  > >
>  > > I want to keep default button "Save,
>  > save and contine and Cancel" like usual.
>  > > With velocity I added a button  to update
>  > my class object on my page and redirect to another one.
>  My
>  > button working well in view mode but I want to use it
>  in
>  > edit mode, then I must save my page before my class
>  object
>  > update and redirection if not all page modifications
>  will be
>  > lost.
>  > >
>  > > My main
>  > problem if I rewrite my code in JS is that I can not
>  update
>  > my class object field attached on my page.
>  > >
>  > > (It's a shame it
>  > doesn't exist an $xwiki.LaunchSaveCurrentPage)
>  > >
>  > > Can I launch
>  > "save page" with javascript? My idea: i launch
>  > save my page in JS from edit mode to view mode with
>  param
>  > (do redirect on another page). With this way I can keep
>  my
>  > nice existant velocity code.
>  > > Do you
>  > know how if I can launch "save page" in JS
>  > then?
>  >
>  > > I see that a
>  > submit in JS go to preview mode, maybe I must modify
>  the
>  > action target of #inline before submit?
>  >
>  > The submit button name (e.g.
>  > name="action_save") is not included by
>  > default when you submit the form using
>  > JavaScript (because the form
>  > may have
>  > multiple submit buttons, like in your case, and the
>  > JavaScript code wouldn't know what button
>  > to indicate in the submit
>  > form unless you
>  > explicitly indicate it). You need to add the button
>  > name to the submit parameters when you make the
>  > AJAX save request.
>  >
>  > Hope
>  > this helps,
>  > Marius
>  >
>
>  _______________________________________________
>  users mailing list
>  users@xwiki.org
>  http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> users@xwiki.org
> http://lists.xwiki.org/mailman/listinfo/users
>
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to