简体   繁体   中英

Reloading the page after submitting POST in a browser

I have an XPage which uses JQuery dialog where I have a button (inside a plain div nothing with JQuery) which creates a new backend "part" when triggered. On the other hand, on the client-side there's validation(which checks that all fields aren't empty). If client-side validation succeed, server-side executes back-end code and new "part" gets created. The problem I've encountered is when new part gets created, if I hit F5 button, browser offers me to repeat the request. If the user clicks "Yes", new part(which is the duplicate of the last one in form) gets created. How do I prevent it?

<xp:button id="save_part_btn"
                        value="+Add part" style="float:right;">
                        <xp:eventHandler event="onclick" submit="true"
                            refreshMode="complete">
                        <xp:this.action><![CDATA[#{javascript:
var estdoc:NotesDocument=database.getDocumentByUNID(doc_source.getDocument().getParentDocumentUNID())
var estPartdoc:NotesDocument=estdoc.getParentDatabase().createDocument()

estPartdoc.replaceItemValue('Form','Estimate_Cost_Part')
estPartdoc.replaceItemValue('Predoc',estdoc.getUniversalID())
estPartdoc.replaceItemValue('$OSN_IsSaved','1')

estPartdoc.replaceItemValue('Title', getComponent('input_part_title').getValue())
estPartdoc.replaceItemValue('TSNB_Title',getComponent('input_tsnb_title').getValue())
estPartdoc.replaceItemValue('TSNB_All',getComponent('input_tsnb_all').getValue())
estPartdoc.replaceItemValue('TSNB_Build_Work',getComponent('input_tsnb_build_work').getValue())
estPartdoc.replaceItemValue('TSNB_Equipment',getComponent('input_tsnb_equipment').getValue())
estPartdoc.replaceItemValue('TSNB_Other_Costs',getComponent('input_tsnb_other_costs').getValue())
estPartdoc.replaceItemValue('TSNB_PIR',getComponent('input_tsnb_pir').getValue())
estPartdoc.replaceItemValue('TSNB_Return',getComponent('input_tsnb_return').getValue())

estPartdoc.replaceItemValue('Current_Title',getComponent('input_current_title').getValue())
estPartdoc.replaceItemValue('Current_All',getComponent('input_current_all').getValue())
estPartdoc.replaceItemValue('Current_Build_Work',getComponent('input_current_build_work').getValue())
estPartdoc.replaceItemValue('Current_Equipment',getComponent('input_current_equipment').getValue())
estPartdoc.replaceItemValue('Current_Other_Costs',getComponent('input_current_other_costs').getValue())
estPartdoc.replaceItemValue('Current_PIR',getComponent('input_current_pir').getValue())
estPartdoc.replaceItemValue('Current_NDS',getComponent('input_current_nds').getValue())
estPartdoc.replaceItemValue('Current_Return',getComponent('input_current_return').getValue())

//var estPartOdoc=new OsnovaUI_document(estPartdoc)
//estPartOdoc.makeDependent(estdoc)

print('new part created with id:'+estPartdoc)
estPartdoc.makeResponse(estdoc)
estPartdoc.save() 


var ag:NotesAgent=database.getAgent('User_CalculateEstimateCost')
ag.runOnServer(doc_source.getDocument().getNoteID())

}]]></xp:this.action>

Server-side code, nothing really special. On submit = "true" I return true if validation succeeds, false if fails

You need to implement the POST-Redirect-GET pattern. Here's an example (from 2010): XPages: Avoid saving duplicate documents on browser refresh .

The crucial part is to include a redirect at the end of your server-side logic. Here's a simple example:

context.redirectToPage(view.getPageName());

In your case the redirect needs to reopen the document so do this:

context.redirectToPage(view.getPageName()+ "?OpenXpage&documentId="+doc_source.getNoteID());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM