【发布时间】:2018-02-06 06:45:58
【问题描述】:
我有一个使用 JQuery 对话框的 XPage,其中我有一个按钮(在纯 div 内没有 JQuery),它在触发时创建一个新的后端“部分”。另一方面,在客户端有验证(检查所有字段是否为空)。如果客户端验证成功,服务器端执行后端代码并创建新的“部分”。我遇到的问题是当创建新部件时,如果我按 F5 按钮,浏览器会提示我重复请求。如果用户单击“是”,则会创建新部分(这是表单中最后一个的副本)。我该如何预防?
<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>
服务器端代码,没什么特别的。
在submit = "true" 上,如果验证成功,则返回 true,如果失败,则返回 false
【问题讨论】:
-
一些代码会有帮助
标签: javascript forms post xpages