Jsf commandButton操作="#{bean.delete(row)}";在datatable中,似乎传递了错误的行

Jsf commandButton操作="#{bean.delete(row)}";在datatable中,似乎传递了错误的行,jsf,primefaces,datatable,Jsf,Primefaces,Datatable,我有一个datatable,它最初没有填充任何数据(一个空列表)。在表的页脚中有一个commandButton,用于向表中添加行。添加行时,行中的最后一个单元格是另一个用于删除该行的commandButton。我的问题是,无论选择了哪一行,“删除”按钮都会不断删除表中的第一行 示例:如果我向表中添加3行并点击第二行最后一个单元格中的delete按钮,action=“#{addAccountBean.deleteFixVendor(dataItem)}”将第一行传递给deleteFixVendor

我有一个datatable,它最初没有填充任何数据(一个空列表)。在表的页脚中有一个
commandButton
,用于向表中添加行。添加行时,行中的最后一个单元格是另一个用于删除该行的
commandButton
。我的问题是,无论选择了哪一行,“删除”按钮都会不断删除表中的第一行

示例:如果我向表中添加3行并点击第二行最后一个单元格中的delete按钮,
action=“#{addAccountBean.deleteFixVendor(dataItem)}”
将第一行传递给
deleteFixVendor
方法,而不是单击的第二行。我不明白为什么不管单击了哪一行按钮,第一行的对象总是传递给delete方法

我的JSF代码:

<h:form>
<f:validateBean disabled="#{!empty param['disableValidation']}" >
<p:panel id="panel" header="Add New Account"  > 
    <p:dataTable var="dataItem" value="#{addAccountBean.account.vendors}" >

        <p:column headerText="Vendor"  >                                
            <p:selectOneMenu value="#{dataItem.vendor}">                
                        <f:selectItems value="#{addAccountBean.menu.fixOption}" />
                    </p:selectOneMenu>
            </p:column>

            <p:column headerText="Monthly Cost"  >
                <p:inputText value="#{dataItem.cost}" />    
            </p:column>

            <p:column headerText="Cost Date"  >
                <p:calendar value="#{dataItem.CDate}" pattern="MM/dd/yyyy" navigator="true" /> 
            </p:column>

            <p:column headerText="Delete" >
            <h:commandButton value="Delete" action="#{addAccountBean.deleteFixVendor(dataItem)}" >
                <f:param name="disableValidation" value="true" />
            </h:commandButton>  
        </p:column> 

        <f:facet name="footer" >
            <h:commandButton value="Add New Vendor" action="#{addAccountBean.addFixVendor}" >
                <f:param name="disableValidation" value="true" />
            </h:commandButton>      
        </f:facet>

    </p:dataTable>          
</p:panel>  
</f:validateBean>
</h:form>

任何建议都将不胜感激。

目前发布的代码看起来不错。对于这个问题唯一可行的解释是
VendorData
类中的一个坏的
equals()
方法。将删除集合中
等于()给定对象的第一项

如果您的(基本)实体具有
id
属性,则应执行以下操作:

@Override
public boolean equals(Object other) {
    return (other != null && getClass() == other.getClass() && id != null)
        ? id.equals(((VendorData) other).id)
        : (other == this);
}

@Override
public int hashCode() {
    return (id != null) 
        ? (getClass().hashCode() + id.hashCode())
        : super.hashCode();
}

你是根据观察还是调试得出结论的?您是否在
deleteFixVendor()
方法上放置了断点并检查传入的
vData
实例?或者您只是观察最终结果并假设传入的
vData
实例“将”是第一行?这个问题更可能是由
VendorData
类中的
equals()
方法损坏引起的,而不是由JSF/EL本身引起的。谢谢@BalusC。这是由于
VendorData
类中的
equals()。现在开始工作了,好的。我贴出了答案。
@Override
public boolean equals(Object other) {
    return (other != null && getClass() == other.getClass() && id != null)
        ? id.equals(((VendorData) other).id)
        : (other == this);
}

@Override
public int hashCode() {
    return (id != null) 
        ? (getClass().hashCode() + id.hashCode())
        : super.hashCode();
}