开发者

Richfaces TabPanel - Avoid multiple submission when user double click on a tab

开发者 https://www.devze.com 2023-01-25 18:06 出处:网络
Let\'s consider this code sample: <rich:tabPanel switchType=\"ajax\"> <rich:tab label=\"tab1\">

Let's consider this code sample:

<rich:tabPanel switchType="ajax">
    <rich:tab label="tab1">
        ...
    </rich:tab>
    <rich:tab label="tab2">
        ...
    </rich:tab>
</rich:tabPanel>

This will create a simple tab panel with 2 tabs, the content of the <rich:tabPanel> is refreshe开发者_如何学JAVAd using Ajax.

So if I am on tab1 and I click on tab2, an Ajax request is sent to the server to get the tab2 content. My concern is that if the user double clicks on tab2, then two Ajax requests will be sent (there will be in fact as many requests sent as the number of times the user quickly clicks on this tab header).

So my question is how to avoid having multiple requests sent, even if the user clicks several times on the tab header?

I tried to set ondblclick="return false;" on both <rich:tab> and <rich:tabPanel>, but it didn't solve my problem.


You can use a popup which shown to user during ajax request. So user cannot click buttons, tabs etc. For example,

<a4j:status id="commonAjaxStatus" onstart="javascript:Richfaces.showModalPanel('ajaxLoadingPanel')" 
    onstop="javascript:Richfaces.hideModalPanel('ajaxLoadingPanel')">
    <f:facet name="start">
        <r:modalPanel id="ajaxLoadingPanel" moveable="false" resizeable="false" width="239" height="40" zindex="1000">
            <h:graphicImage  value="../img/ajax-loader.gif" />
        </r:modalPanel>
    </f:facet>
    <f:facet name="stop">
    </f:facet>
</a4j:status>

If you insert this code into your page, on ajax requests a popup will be opened and when the request finishes, popup will disappear.

0

精彩评论

暂无评论...
验证码 换一张
取 消