8 Replies Latest reply on Mar 5, 2008 12:02 PM by Jens Mueller

    modal panel as confirmation box?

    Jens Mueller Novice

      I'm trying to get a modal panel act as a confirmation box. the result (yes/no) decides whether a specific item from a datatable is deleted or not. the problem? it's not working ;) I use an a4j:commandButton and an actionlistener that catches the item id. has anyone an idea how to get this workin? thanks in advance, jens

        • 1. Re: modal panel as confirmation box?
          Justin Cobb Newbie

          I've done this multiple times in my site without any problems. What is it about this that isnt working, are you just missing a rerender? Do you have any code you can post?

          • 2. Re: modal panel as confirmation box?
            Jens Mueller Novice

            my code looks similar as following:
            <h:commandButton actionListener="#{AdminHandler.delAdmin}" value="#{msg.delete}" onclick="Richfaces.showModalPanel('delAdmConf')">
            <f:attribute name="selectedId" value="#{item.id}"/>
            </h:commandButton>

            For a normal js-confirmation-box deletion or non-deletion would dependent on the return value of the js-function. I've tried to call the AdminHandler.delAdmin function from within the modalPanel-code after the confirmation, however the respective item.id then gets lost.

            • 3. Re: modal panel as confirmation box?
              Jens Mueller Novice

              ..ups..i use an a4j:commandButton of course..

              • 4. Re: modal panel as confirmation box?
                mustafa karakaya Newbie

                there is a similar process in one of my works. i will try to explain my method here. in fact when the button or image or link (whatever on that column of table) of a row is clicked, i put the index on a sessionbean. after that using oncomplete property of a4j support open the modal panel. after that if the user clicks on cancel just close the modal panel, if user confirms that call the delete action and it gets the selected index from session bean and deletes it. dead simple in fact:) here the sample codes from my work. hope this answer helps:

                when the table row clicked: call action that writes the index in session bean

                <a4j:support action="#{APage.submitDeleteIndex}" event="onClick" oncomplete="Richfaces.showModalPanel('AreYouSureModalPanel')"/>

                public void submitDeleteIndex(){
                 int index = gelSelectedRow();
                 getActionsSessionBean().setActionTypeDelete(true);
                 getActionsSessionBean().setDeleteIndex(index);
                 }

                if cancel button of modal panel is clicked: just close modal panel
                onclick="Richfaces.hideModalPanel('AreYouSureModalPanel')"

                if yes button of modal panel is clicked: call action that deletes item
                <a4j:support action="#{APage.deleteSelectedItem}" event="onclick" oncomplete = "Richfaces.hideModalPanel('AreYouSureModalPanel')" reRender="A_PANEL"/>

                public void deleteSelectedMenuItem(){
                 int rowIndex = getActionsSessionBean().getDeleteIndex();



                • 5. Re: modal panel as confirmation box?
                  Jens Mueller Novice

                  thanks genkito, your post helped me a lot. my current solution is to save the selected item in the sessionmap and call the delete function as shown in your example from within the modal panel.
                  regards, jens

                  • 6. Re: modal panel as confirmation box?
                    Pierre Masse Newbie

                    This topic's is very interesting.

                    I'm trying to implement a modalPanel to replace a javascript Confirm().
                    But I can't put my finger on how to implement that kind of popup dialog.

                    The way I have it now (without richfaces) is:

                    <h:commandButton id="submitButtonAppl" action="#{portFolioAction.verifyAndSubmitForm}" onclick="var answer=of_isSubmitPermitted('#{navigationBean.languageSite}');if (answer){of_setInputField(document.forms[0],'form_id',#{item.form_id});this.submit();} else {return false;};" type="button">

                    My javascript method, of_isSubmitPermitted(), is basically a call to Confirm().

                    As you can see, the Action will not be executed because the page won't be submitted, if the user clicks the popup's cancel button.

                    I'd really appreciate it if someone could help me out with this. I tried a bunch of things but nothing works the way it is currently implemented.

                    Thanks

                    • 7. Re: modal panel as confirmation box?
                      Luiz Aguiar Newbie

                      It's possible to after the call oncomplete="Richfaces.hideModalPanel('id')", I redirect to another page?

                      Like an exit confirm dialog.

                      • 8. Re: modal panel as confirmation box?
                        Jens Mueller Novice

                        @ massep: I'd split the whole process into a confirm and an action part. The confirm part only calls the richfaces showpanel function (via onclick) whereas the panel itself calls the respective action or just vanishes. if you have anything on the screen that is influenced by your action i'd recommend the <a4j:commandButton> as you can reRender the affected area on your screen (looks way cooler ;)
                        @laguiar: action="targetpage" on your commandButton and a corresponding navigation rule in your faces-conf is just one way to do that.