在JSF中:ui:repeat confirmdialog获取列表中最后一个元素的id

时间:2012-06-18 19:54:49

标签: jsf uirepeat

我有这个命令按钮

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

                                                </p:commandButton>

这是确认对话框

<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>

两者都在ui中:重复,当我点击确认对话框中的“肯定”按钮时,它会获取ui:repeat列表中最后一个元素的profileId。

我尝试了f:param方法然后尝试在bean中获取请求参数但是徒劳无功。它做同样的事情。

需要帮助。 感谢

修改

我已将网页内容更改为

<?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>
在BalusC的回复之后。但它不起作用,使用update =“:interestExpressionsForm:confirmDialog” 确认对话框打开然后立即关闭。

1 个答案:

答案 0 :(得分:2)

<p:confirmDialog>放在<ui:repeat>之外。你只需要一个,而不是多个。只需ajax - 根据按下的按钮相应地更新对话框的内容。