【问题标题】:Multiple rows are getting selected in P:DataTable even when Single Selection Mode is enabled即使启用了单选模式,也会在 P:DataTable 中选择多行
【发布时间】:2015-06-21 01:30:46
【问题描述】:

我有一个 JSF-EJB 应用程序,我在其中使用单选模式。数据表是用户单击“保存”按钮时出现的对话框的一部分。第一次,在 DataTable 中没有选择正确的行。现在当用户选择一行时。并关闭此对话框。并再次打开此对话框。 DataTable 中的两行都被选中。

下面是正在使用的代码。 请帮忙。

XHTML:

                    <p:dataTable var="address" id="confirmDataTable"
                        value="#{householdHomeAddressBean.normalizedAddressList}"
                        selection="#{householdHomeAddressBean.selectedAddress}"
                        rowKey="#{address.id}" styleClass="confirmAddTable">
                        <p:column selectionMode="single"
                            style="width:40px;text-align:center" id="radioCol">
    </p:column>
                        <p:column >
                        <p:outputLabel value="#{address.message}"/>
                        </p:column>
                        <p:column headerText="Street Address" id="headerStreet">
                            <p:outputLabel value="#{address.addrLine1}" />  <p:outputLabel value="#{address.addrLine2}" />,

                        </p:column>
                        <p:column headerText="County" id="headerCounty">
                            <p:outputLabel value="#{address.countyName}" />
                        </p:column>

                    </p:dataTable>

                    <p:commandButton styleClass="fl-right btn" value="OK" process="@form" validateClient="true" update="@form"
                        action="#{householdHomeAddressBean.saveAddress}">

                    </p:commandButton>
                    <p:commandButton styleClass="fl-left btn" value="Cancel"
                        onclick="PF('addressDialog').hide();"></p:commandButton>
                </p:dialog>

在托管 Bean 中:

public void saveAddress() {
    context = RequestContext.getCurrentInstance();
    context.execute("PF('addressDialog').hide();");

//************************持久性代码**************///////// //
}

请告诉我我做错了什么。

【问题讨论】:

  • 添加属性 selectionMode="single"
  • 启用行选择,但我需要单选按钮作为表格的一列...这就是为什么添加此代码:

标签: jsf primefaces datatable selection ejb-3.0


【解决方案1】:

此问题已解决。我只是设置 selectedAddress=null;它工作得很好:)

【讨论】:

  • 奇怪……你用的是什么PF版本?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-02
  • 1970-01-01
  • 2015-06-13
  • 1970-01-01
  • 2017-05-12
  • 2012-06-06
相关资源
最近更新 更多