簡體   English   中英

點擊后保留網址參數<h:commandButton>

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM