[英]Keep url parameters after clicking <h:commandButton>
我有一个页面,它使用id作为url参数,并使用它来获取对象并显示有关它的数据。 在此页面上,我们有一个包含文件上传组件的模式,因此我们无法使用ajax处理保存。 相反,我们这样做:
<rich:modalPanel domElementAttachment="parent" id="profilePanel" styleClass="popUp" resizeable="false" moveable="false" autosized="true" zindex="200" top="-10">
<a4j:form enctype="multipart/form-data" id="profilePanelFormId">
<q:box title="Edit Advocacy Profile" width="width6x" wantFocus="true">
<s:div id="profilePanelForm">
<rich:messages rendered="#{messagesUtil.errorsExist}"/>
<a4j:include viewId="/panel/advocacy/advocateProfileEdit.xhtml"/>
</s:div>
<h:commandButton id="cancel" immediate="true" value="Cancel" action="#{advocateManager.cancelEditCommitment}" styleClass="button cancel" tabindex="100"/>
<h:commandButton id="save" value="Save" action="#{advocateManager.saveCommitment}" styleClass="submit" tabindex="101"/>
</q:box>
</a4j:form>
</rich:modalPanel>
我们像这样在pages.xml中填充参数:
<page view-id="/advocacy/advocateCommitmentView.xhtml" login-required="true">
<param name="confirmationCode" value="#{advocateManager.commitmentId}"/>
</page>
到现在为止还挺好。 我们遇到的问题是,当用户单击“保存”或“取消”时,URL被重写而没有必要的id参数。 如果用户随后刷新页面,则由于没有此键,将引发错误。 有谁知道我不用ajax就能调用我的save方法,而仍然保留url参数或拦截该调用并重新添加该参数吗?
将?includeViewParams=true
放在操作字符串的末尾。
发生这种情况是因为<h:commandButton/>
发布了表单,并且表单后的URL中不包含参数。 要添加参数,请创建一个重定向到同一页面的导航规则:
<navigation from-action="#{advocateManager.saveCommitment}">
<rule>
<redirect view-id="/same-page.xhtml" />
</rule>
</navigation>
进行重定向时,页面参数将被编码并添加到URL。 请注意,这要求在重定向完成后填充#{advocateManager.commitmentId}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.