1

I've this command button

<p:commandButton onclick="confirmation1.show()"
                                                                 id="delFriend" title="Delete #{userFriend.profileFullname}" icon="ui-icon ui-icon-trash" >

                                                </p:commandButton>

And this is the confirm dialog

<p:confirmDialog id="confirmDialog" message="Are you sure you want to delete this friend ?"
                                                             header="Deleting friend" severity="alert" widgetVar="confirmation1">


                                                <p:commandButton id="confirm" value="Yes Sure" oncomplete="confirmation1.hide()"
                                                                 action="#{messagesManagedBean.deleteFriend}">
                                                    <f:param value="#{profileId}" name="profileId" />
                                                </p:commandButton>
                                                <p:commandButton id="decline" value="Not Yet" onclick="confirmation1.hide()" type="button" />
                                            </p:confirmDialog>

Both are inside the ui:repeat, when i click on the "Yes sure" button in the confirm dialog, it takes the profileId of the last element present in the ui:repeat list.

I tried f:param method and then tried to get the request parameters in the bean but in vain. it does the same thing.

Help needed. thanks

EDIT

I've changed the page content to

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui" 
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="../Styles/homepage-style.css" />
        <link rel="stylesheet" type="text/css" href="../Styles/profile.css" />
        <title>Shadi Bandhan | We find the best match for you</title>
    </h:head>

    <h:body>

        <div id="header">
            <ui:insert name="header" >
                <ui:include src="header.xhtml" />
            </ui:insert>
        </div>
        <div id="main-content">
            <p:growl autoUpdate="true" />
            <div id="left-pane">

                <div id="profile-info-area">
                    <ui:insert name="profile_info_area" >
                        <ui:include src="profileInfoArea.xhtml" />
                    </ui:insert>
                </div>

                <div id="home-main-area">
                    <div id="interests-expressions-wrapper">

                        <div id="interests-expressions-header">

                            <div id="ie-heading">
                                Friends
                            </div>

                        </div>
                        <div id="interests-expressions">

                            <h:form id="interestExpressionsForm">

                                <p:confirmDialog id="confirmDialog" message="Are you sure you want to delete this friend ?"
                                                 header="Deleting friend" severity="alert" widgetVar="confirmation1">


                                    <p:commandButton id="confirm" value="Yes Sure" oncomplete="confirmation1.hide()"
                                                     action="#{messagesManagedBean.deleteFriend(userFriend.profileId)}">
                                    </p:commandButton>
                                    <p:commandButton id="decline" value="Not Yet" onclick="confirmation1.hide()" type="button" />
                                </p:confirmDialog>

                                <ui:repeat id="interestsRepeator" var="userFriend" value="#{messagesManagedBean.userFriends}">

                                    <center><img class="h-diff" src="../images/differentiator-profile.jpg" width="437" height="1" /></center>
                                    <div class="intExpression">
                                        <div id="senderImg">
                                            <img class="senderImg" src="../images/profile-pic.jpg" width="50" height="50" />
                                        </div>

                                        <div id="intExpression-area">

                                            <div id="senderName">
                                                <p:commandLink id="senderNameLink" styleClass="senderName" value="#{userFriend.profileFullname}"  action="#{myProfileManagedBean.loadProfileFrontInformation(userFriend.profileId)}"></p:commandLink>
                                            </div>
                                            <div id="intExpression-body">
                                                #{userFriend.profileAge} <br />
                                                #{userFriend.profileReligion} <br />
                                                #{userFriend.profileLocation} <br />

                                            </div>

                                            <div id="interest-response-area">

                                                <p:commandButton onclick="confirmation1.show()" update=":interestExpressionsForm:confirmDialog"
                                                                 id="delFriend" title="Delete #{userFriend.profileFullname}" icon="ui-icon ui-icon-trash" >
                                                    <f:param value="#{userFriend}" name="userFriend" />
                                                </p:commandButton>
                                            </div>

                                        </div>
                                    </div>
                                </ui:repeat>

                            </h:form>

                        </div>



                    </div>
                </div>
            </div>

            <div id="right-pane">
                <ui:insert name="right-pane" >
                    <ui:include src="right-pane.xhtml" />
                </ui:insert>
            </div>
        </div>

        <div id="footer">
            <ui:insert name="footer" >
                <ui:include src="footer.xhtml" />
            </ui:insert>
        </div>

    </h:body>
</html>

after the reply of BalusC. But it doesn't work, with the update=":interestExpressionsForm:confirmDialog" the confirm dialog opens and then closes immediately.

Mudassir Shahzad
  • 542
  • 2
  • 16
  • 32

1 Answers1

2

Put the <p:confirmDialog> outside the <ui:repeat>. You need only one, not multiple. Just ajax-update the dialog's content accordingly based on the pressed button.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I did this before, but didn't work, when you answered i tried it again but not working. Please see the Edit portion in the question now. – Mudassir Shahzad Jun 18 '12 at 21:49
  • Update the dialog's content instead of the entire dialog. Note that common practice is to put the dialog outside any form as well and give it its own form. You can then update that form instead. – BalusC Jun 18 '12 at 21:51