Thursday, June 3, 2010

#9: Issue in XPage: Xpage refresh results in creation of duplicate documents

I am currently facing an issue in Xpages which is haunting me....

Initially I had issues with Required fields getting validated in every server refresh. I fortunately stumbled upon Tommy Valand's blog and found beautiful solutions to many issues. When I used the code and fixed the same.. this monster arrived at my door step...

A brief description would be,

1.Open an Xpage which is bound to some data source and has a submit button which saves the underlying document.


2. Save the XPage by clicking the submit button and cross check with the view that displays the underlying document in notes

3.Now press F5 on key board. You will get a prompt saying the following message,

The page you are trying to view contains POSTDATA. If you resebd the data,
any action the form carried out(such as a search or online purchase) will be
repeated. To resend the data, click OK. Otherwise, click Cancel.


4.Clicking Ok on this prompt will create a duplicate document

This is one issue that is haunting me in my current project

3 comments:

  1. The Solution to this issue is posted by Tommy valand in the following url:
    http://dontpanic82.blogspot.com/2010/
    06/xpages-avoid-saving-duplicate-documents.html

    The solution is to add a execute script action to the submit button, and call the following function,

    function redirectToCurrentDocument( switchMode:boolean ){
    if( typeof currentDocument === 'undefined' ){ return; }
    // Gets the name of the XPage. E.g. /Person.xsp
    var page = view.getPageName();

    // Gets the unid of the current document
    var unid = currentDocument.getDocument().getUniversalID();

    // Sets/changes the action according according to the mode the document is in
    var isEditable = currentDocument.isEditable();
    if( switchMode ){ isEditable = !isEditable; } // false -> true / true -> false
    var action = ( isEditable ) ? 'editDocument' : 'openDocument';

    // Open the current document via a get request
    context.redirectToPage( page + '?documentId=' + unid + '&action=' + action );
    }

    ReplyDelete
  2. Just wanted to let you know that I've extended the code so that it carries extra parameters (other than action and documentId) when redirecting.

    Not sure if this helps you in any way. A colleague of mine needed this.

    ReplyDelete
  3. Thank you very much Tommy. Sure am learning a lot from you

    ReplyDelete