Jsf 2 为什么ActionListener不适用于JSF2.1JavaEE

Jsf 2 为什么ActionListener不适用于JSF2.1JavaEE,jsf-2,Jsf 2,我对ActionListener有问题。这是带有JSF2.1 dataTable组件的.xhtml文件的一部分: <h:column> <f:facet name="header"> <h:outputText value="Delete"></h:outputText>

我对ActionListener有问题。这是带有JSF2.1 dataTable组件的.xhtml文件的一部分:

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Delete"></h:outputText>
                        </f:facet>
                        <h:commandButton value="delete" action="#{productManagedBean.delete}" actionListener="#{productManagedBean.setSelectedProduct}">
                            <f:attribute name="selectedProduct" value="#{product}"></f:attribute>
                        </h:commandButton>
                    </h:column>

                </h:dataTable>
            </h:form>
它当然可以工作,产品列表显示,我可以单击commandButton设置我要删除的产品并强制方法删除-但当我要为客户显示列表时,我使用以下方法,其中参数为Customer对象:

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Delete"></h:outputText>
                        </f:facet>
                        <h:commandButton value="delete" action="#{productManagedBean.delete}" actionListener="#{productManagedBean.setSelectedProduct}">
                            <f:attribute name="selectedProduct" value="#{product}"></f:attribute>
                        </h:commandButton>
                    </h:column>

                </h:dataTable>
            </h:form>
EJB组件:

                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Delete"></h:outputText>
                        </f:facet>
                        <h:commandButton value="delete" action="#{productManagedBean.delete}" actionListener="#{productManagedBean.setSelectedProduct}">
                            <f:attribute name="selectedProduct" value="#{product}"></f:attribute>
                        </h:commandButton>
                    </h:column>

                </h:dataTable>
            </h:form>
@Stateless
public class ProductBean implements ProductBeanLocal {

@PersistenceContext(unitName = "CustomerServicePU")
EntityManager em;

@Override
public List<Product> getList() {
    List<Product> list = em.createQuery("SELECT p FROM Product p").getResultList();
    return list;
}

@Override
public List<Product> getList(Customer c) {
    List<Product> list = em.createQuery("SELECT p FROM Product p WHERE p.customer.id = :id").setParameter("id", c.getId()).getResultList();
    return list;
}
有人知道它为什么不工作吗?

selectedCustomer从未设置。我看不见。但是,您尝试根据所选客户获得一些结果。!它们是执行业务逻辑的错误位置。你的具体问题在第4点重复并得到了回答。
                    <h:column>
                        <f:facet name="header">
                            <h:outputText value="Delete"></h:outputText>
                        </f:facet>
                        <h:commandButton value="delete" action="#{productManagedBean.delete}" actionListener="#{productManagedBean.setSelectedProduct}">
                            <f:attribute name="selectedProduct" value="#{product}"></f:attribute>
                        </h:commandButton>
                    </h:column>

                </h:dataTable>
            </h:form>