简体   繁体   中英

Show rich:popupPanel on click of rich:tab

One page contains the rich face tab panel and having 4 tabs. In one of the tab, I have text box and save button . Without saving the data If i move to another tab, It should show the popup saying unsaved data and prevent the navigation.

I tried calling a popup using different java script loading attributes of rich:tabPanel but not serving the purpose.

Here is the code

    <rich:tabPanel onclick="#{rich:component('confirmation')}.show();return false"  switchType="ajax"  id="wizardTab" itemChangeListener="#{bean.tabChange}" activeItem="#{bean.activeTab}">
    <rich:tab id="tab1" 
              // tab1

    </rich:tab>
    <rich:tab id="tab2" 


    </rich:tab>
    <rich:tab id="tab3" 


    </rich:tab>

    <rich:tab id="tab4" 
                        <h:inputText id="test" 
                                     styleClass="span2" maxlength="25"
                                     value="#{bean.rowForChange.code}">
                                     <f:ajax event="blur" execute="@this"/>
                        </h:inputText>
                        <h:commandButton value="Update" styleClass="button"
                                                     style="width:160px"
                                                     action="#{bean.updtae}">
                                        <a4j:ajax execute="paramValue"
                                                  render="table simeditPnl" />
                        </h:commandButton>

    </rich:tab>

</rich:tabPanel>

    <rich:popupPanel render="#{jCRDataRefreshManagement.updateStatus}" id="confirmation" modal="false" autosized="true" resizeable="false">
           <f:facet name="header">Confirmation</f:facet>
       <h:panelGrid>
          <h:panelGrid columns="2">
             <h:graphicImage value="/alert.png" />
         <h:outputText value="You have unsaved changes. Are you sure?" style="FONT-SIZE: large;" />
          </h:panelGrid>
          <h:panelGroup>
             <input type="button" value="OK"
          onclick="#{rich:component('confirmation')}.hide();submit();return false" />
         <input type="button" value="Cancel"
          onclick="#{rich:component('confirmation')}.hide();return false" />
          </h:panelGroup>
       </h:panelGrid>
    </rich:popupPanel>

If any unsaved data on the text box on tab 4 and tried to click on any other tab it should stay in the tab 4 and show the confirmation poupup as above.

With this implementation my popup is opening whenever I am clicking the tab.

Please point out the mistake I am doing or give the suggestion for above scenario. Any help appretiated

Instead of click use onbeforeitemchange and return false if you don't want the tabs to switch.

If you want to delay the switching use something like this:

saveTabs = function(event) {
    oldItem = event.rf.data.oldItem,
    newItem = event.rf.data.newItem;
}

<rich:tabPanel id="tabPanel" onbeforeitemchange="saveTabs(event); return false;" >

And when you decide to switch use:

RichFaces.component("form:tabPanel").__itemsSwitcher().exec(oldItem, newItem);

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